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

Checkboxlist in the edititemtemplate check default

1 Answer 19 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Erin
Top achievements
Rank 1
Erin asked on 10 Oct 2013, 02:08 PM
Hi
I have a checkboxlist in the edititemtemplate of my radgrid.i want its value to be checked to the default value on edit.

Thanks,
Erin.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 10 Oct 2013, 02:14 PM
Hi Erin,

Please try the following code snippet.

ASPX:
<telerik:GridTemplateColumn HeaderText="ShipCity">
    <ItemTemplate>
        <%# Eval("ShipCity")%>
    </ItemTemplate>
    <EditItemTemplate>
        <asp:CheckBoxList ID="CheckBoxList1" runat="server" DataSourceID="SqlDataSource2"
            DataTextField="ShipCity" DataValueField="ShipCity">
        </asp:CheckBoxList>
    </EditItemTemplate>
</telerik:GridTemplateColumn>
 <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:Northwind_newConnectionString3 %>"
SelectCommand="SELECT distinct [ShipCity] FROM [Orders]"></asp:SqlDataSource>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
  {
   if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
      GridEditableItem edit = (GridEditableItem)e.Item;
      CheckBoxList list = (CheckBoxList)edit.FindControl("CheckBoxList1");
      list.SelectedValue = DataBinder.Eval(edit.DataItem, "ShipCity").ToString();
     }
  }

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