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

Hi i hav telrik radgrid inside it i hav dropdown,

2 Answers 41 Views
Grid
This is a migrated thread and some comments may be shown as answers.
siva
Top achievements
Rank 1
siva asked on 28 Oct 2010, 04:33 PM
Hi i hav telrik radgrid inside it i hav dropdown,
on dropdown selected value,  my other columns in corresponding same rows  values shuld be updated.
give me solution for this in both client and server side levels
can  any one help me.

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 Oct 2010, 06:37 AM
Hello Siva,

The following sample code shows how you can achieve this in server side. Attach SelectedIndexChanged event to DropDownList and using NamingContainer property of DropDownList access the grid item. Then find out corresponding control which you want to change using FindControl method and update its value.

ASPX:
<Columns>
   <telerik:GridTemplateColumn>
        <ItemTemplate>
            <asp:DropDownList ID="DropDownList1" runat="server"
              DataSourceID="SqlDataSource1" DataTextField="EmployeeID"
              DataValueField="EmployeeID" AutoPostBack="True"
              OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
            </asp:DropDownList>
        </ItemTemplate>
    </telerik:GridTemplateColumn>
    <telerik:GridTemplateColumn>
        <ItemTemplate>
            <asp:Label ID="Label1" runat="server" Text='<%#Eval("FirstName") %>'></asp:Label>
        </ItemTemplate>
    </telerik:GridTemplateColumn>
</Columns>

C#:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
   {
       DropDownList list = (DropDownList)sender;
       GridDataItem item = (GridDataItem)list.NamingContainer;
       Label lb = (Label)item.FindControl("Label1");
       lb.Text = "new value";
   }

If you want to achieve this in client side, attach 'onChange' client event to DropDownList by passing item index to event handler. In that event handler identify the corresponding row using this index value and find out the control in that row that you wants to update.

Java Script:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
      if (e.Item is GridDataItem)
       {
           GridDataItem item = (GridDataItem)e.Item;
           DropDownList list = (DropDownList)item.FindControl("DropDownList1");
           list.Attributes.Add("onChange","OnSelectedIndexChange('"+item.ItemIndex+"');");
       }
    }

Java Script:
<script type="text/javascript">
   function OnSelectedIndexChange(rowindex) {
        var grid = $find("<%=RadGrid1.ClientID %>");
        var MasterTable = grid.get_masterTableView();
        var row = MasterTable.get_dataItems()[rowindex];
        row.findElement("Label1").innerHTML = "new value";
    }
</script>

Thanks,
Princy.
0
siva
Top achievements
Rank 1
answered on 29 Oct 2010, 07:20 AM
Thank you princy, let me start trying it.
Tags
Grid
Asked by
siva
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
siva
Top achievements
Rank 1
Share this question
or