This is a migrated thread and some comments may be shown as answers.

Filling columns according to dropdown in first column in radGrid

4 Answers 76 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mario
Top achievements
Rank 1
Mario asked on 11 Oct 2012, 11:51 AM
Hi,
this is the first time i touch asp.net and telerik. 
I have been trying to figure something out for quite a while :

i have a table in a database: 
ID NAME  NICK
123  Mario        Mar
234  Maria        Mia
.
. and so on...

I am starting out with an empty radgrid containing a template column that has a radComboBox inside. that radComboBox is populated from SqlDataSource (the ID). I have two more columns, Name and Nickname that all i need them to display is the Name and Nickname according to that table in the database that is in a Dataview variable called data now. it does not matter if the Name and Nickname columns are read only textboxes or labels.... the RadGrid is editable in-line. 

how can i display the name and nickname when the user selects an ID from the RadComboBox  while in edit mode and save that line in the table ? 

Example: in edit mode if i select the ID 123 it will instantly display Mario and Mar in the corresponding columns. and when I click the Insert button it will be inserted in the table. and then finally if i click the submit button it will send the table to the database... but thats another issue.. 

THANK YOU HELPERS ! ( just take it easy on me.. I'm still very new and learning.. )

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 12 Oct 2012, 06:07 AM
Hi Mario,

Here is the sample code that I tried based on your scenario. You can set the column's visibilty on selecting an item from the combobox.
aspx:
<telerik:RadGrid ID="RadGrid1" AutoGenerateEditColumn="true" DataSourceID="SqlDataSource2" runat="server" AutoGenerateColumns="false">
 <MasterTableView>
   <Columns>
          <telerik:GridTemplateColumn>
               <ItemTemplate>
                   <telerik:RadComboBox ID="RadComboBox1" runat="server" DataTextField="LastName" DataValueField="LastName"   DataSourceID="SqlDataSource2"   AutoPostBack="true" onselectedindexchanged="RadComboBox1_SelectedIndexChanged" ></telerik:RadComboBox>
              </ItemTemplate>
          </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn UniqueName="LastName" Display="false">
                 <ItemTemplate>
                      <asp:TextBox ID="TextBox1" ReadOnly="true"  Text='<%#Eval("LastName") %>' runat="server"></asp:TextBox>
                  </ItemTemplate>
                 </telerik:GridTemplateColumn>
   </Columns>
  </MasterTableView>
 </telerik:RadGrid>
C#:
protected void RadComboBox1_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
   {
       RadGrid1.MasterTableView.GetColumn("LastName").Display = true;
   }

Thanks,
Shinu.
0
Mario
Top achievements
Rank 1
answered on 12 Oct 2012, 02:00 PM
Thank you for your reply but that is not what i am looking to do..

when i click on "add a record", in order to add a row to the table, the in-line editor comes, then there's a combobox under ID column, and and empty readonly textbox or label under Name and another empty label under Nickname. When the user selects an ID from the combobox, while still in the editor, the labels under Name and Nickname will be filled with text, that is the name and nickname from the table in the database that match the ID selected in the combobox. ( i think this requires using a javascript to fill the labels right when the client selects an ID.. )

thanks !
0
Mario
Top achievements
Rank 1
answered on 15 Oct 2012, 07:08 AM
If i am not clear enough, please ask, i will try to explain in a different manner. thank you !
0
Shinu
Top achievements
Rank 2
answered on 15 Oct 2012, 07:13 AM
Hi,

You can use the following server side approach.
C#:
protected void RadComboBox1_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
{
        RadComboBox combo=(RadComboBox)sender;
        GridEditableItem item = (GridEditableItem)combo.NamingContainer;
        TextBox txt = (TextBox)item.FindControl("TextBox1");
        Label lbl = (Label)item.FindControl("Label1");
        txt.Text = combo.SelectedValue.ToString();
        lbl.Text = combo.SelectedItem.Text;
}

Thanks,
Shinu.
Tags
Grid
Asked by
Mario
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Mario
Top achievements
Rank 1
Share this question
or