I have looked far and wide but found nothing to help me with this. My datagrid has a hidden column with an id number bound to it. Then there is a column of radio buttons. (Then more columns of data.) If the value of the "priority" field in the data is 1, then that item's radio button should be selected. (Eventually, I want users to be able to select some other row to be #1, but I will deal with that later.) So I have this in a templated column in the data grid:
. . .
<itemtemplate>
<asp:radiobutton id="lead_rad" runat="server" oncheckedchanged="NewPriority"></asp:radiobutton>
</itemtemplate>
. . .
and this code in the OnItemDataBound handler:
Expand|Select|Wrap|Line Numbers
- RadioButton rb;
- Int16 p;
- if (e.Item.ItemType == ListItemType.Item|e.Item.ItemType == ListItemType.AlternatingItem){
- p = Convert.ToInt16(DataBinder.Eval(e.Item.DataItem, "priority"));
- rb = (RadioButton)e.Item.Cells[1].FindControl("lead_rad");
- if(p==1){rb.Attributes.Add("checked","true");}
- ...}
<span checked="true"><input id="news_dg__ctl5_lead_rad" type="radio" name="news_dg:_ctl5:news_dg:_ctl5:lead_rad" value="lead_rad" /></span>
I dunno where the span comes from, especially since I am adding a "confirm" pop-up to the delete button in the same handler and it works like a charm.
Any help welcome, abuse tolerated.