This is a migrated thread and some comments may be shown as answers.
Grid Toggle Button
1 Answer 38 Views
This is a migrated thread and some comments may be shown as answers.
Ken
Top achievements
Rank 1
Ken asked on 11 Apr 2011, 08:34 PM

I have a toggle button in a grid and would like to set its initial setting dependant on a Boolean in the database. Is there a way to bind it or set it via code.

 

Thanks

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 12 Apr 2011, 05:49 AM
Hello,
Here is a sample code to achieve the same.
aspx:
<telerik:GridTemplateColumn UniqueName="ToggleButton">
  <ItemTemplate>
  <telerik:RadButton ID="btnToggle" runat="server" ToggleType="CheckBox" ButtonType="ToggleButton">
  </telerik:RadButton>
 </ItemTemplate>
</telerik:GridTemplateColumn>

C#:
protected void grdEmail_ItemDataBound(object sender, GridItemEventArgs e)
  {
      if (e.Item is GridDataItem)
      {
          GridDataItem item = (GridDataItem)e.Item;   RadButton rdBtn = (RadButton)item.FindControl("btnToggle");
          DataRowView row = (DataRowView)e.Item.DataItem;//accessing the value from data rowview
         rdBtn.Checked =Convert.ToBoolean(row["bool"]);
      }
   }

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