Quantcast
Channel: Telerik Forums RSS
Viewing all articles
Browse latest Browse all 94857

add dynamic radiobutton on rad grid

$
0
0

I need to add a custom radio button control that I created based on an if condition to my GridView. My radiobutton will be enabled or disabled based on this condition and will have the text changed as well.I'm trying to figure out how to add a radiobutton object into my data row instead of a stringdt.Columns.Add("FirstName").

 

<telerik:RadGridrunat="server"ID="grd1"OnNeedDataSource="grd1_NeedDataSource">
<MasterTableViewAutoGenerateColumns="False">
<Columns>
<telerik:GridTemplateColumnHeaderText="Radiobutton header"UniqueName="col1">
<ItemTemplate>
<asp:RadioButtonID="rbType"runat="server"Text='<%# DataBinder.Eval(Container.DataItem, "rbEnableorDisable")%>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
 
<telerik:GridTemplateColumnHeaderText="FirstName header"UniqueName="col2">
<ItemTemplate>
<asp:LabelText='<%# DataBinder.Eval(Container.DataItem, "Name")%>' runat="server" />
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>

 Codebehind


dt= NewDataTable
dt.Columns.Add("rbEnableorDisable")
dt.Columns.Add("FirstName")
 
Dimrb AsRadioButton
rb = NewRadioButton
 
Foreach item in itemlist //some data iteration declared elsewhere
dr = dt.NewRow()
If(Condition)
rb.Text = "Should be Disabled"
rb.Enabled = False
Else
rb.Text = "Should be Enabled"
rb.Enabled = True
Endif
 
dr.Item("FirstName") = item.FirstName
dr.Item("rbEnableOrDisable") = rb//?Code for inserting a radio button object
dt.Rows.Add(dr)
Next
 
Withgrd1
.DataSource = dt
.DataBind()
EndWith

 So far with this code I am only able to display the radiobutton text if i havedr.Item("rbEnableOrDisable") = rb.Text.I need to display the whole radiobutton object(show the text and if it's enabled or disabled among others)I triedLocationData.Columns.Add(New DataColumn("rbType", GetType(RadioButton)))but it seems I need to append to the ItemTemplateAlso tried adding the whole column dynamic with:grd1.Controls.Add(rb)

 


Viewing all articles
Browse latest Browse all 94857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>