我有一个问题,我希望在单选按钮选择更改的情况下在后端检索数据绑定字段reg_id的值。请告诉我,我做错了。
<asp:GridView ID="GridView1" runat="server" class="gridview" AutoGenerateColumns="False" DataKeyNames="reg_id" onrowcommand="GridView1_RowCommand">
<Columns>
<asp:BoundField DataField="reg_id" Visible="false" />
<asp:TemplateField>
<ItemTemplate>
<div style="width:100px; float:left;">
<asp:Label ID="Label2" runat="server" Text="<%# bind('username') %>" ></asp:Label>
</div>
<div style="width:100px; float:left;">
<asp:Label ID="Label4" runat="server" Text="<%# bind('country') %>" ></asp:Label>
</div>
<div style="width:100px; float:left;">
<asp:Label ID="Label6" runat="server" Text="<%# bind('city') %>" ></asp:Label>
</div>
<div style="width:100px; float:left;">
<asp:Label ID="Label7" runat="server" Text="<%# bind('locality') %>" ></asp:Label>
</div>
<div style="width:100px; float:left;">
<asp:Label ID="Label5" runat="server" Text="No of Posts"></asp:Label>
</div>
<asp:RadioButton GroupName="a" ID="RadioButton1" runat="server" AutoPostBack="true" OnCheckedChanged="change_attributes" value='<%#Eval("reg_id")%>' />
<asp:RadioButton GroupName="a" ID="RadioButton2" runat="server" AutoPostBack="true" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
后端代码:这里我希望通过对象发送者值属性检索数据绑定字段reg_id值的值。
for (int i = 0; i < GridView1.Rows.Count; i++)
{
RadioButton radio1 = (RadioButton)GridView1.Rows[i].FindControl("RadioButton1");
RadioButton radio2 = (RadioButton)GridView1.Rows[i].FindControl("RadioButton2");
string id = "";
RadioButton btn = (RadioButton)sender;
id = btn.Attributes.ToString();
}
答案 0 :(得分:3)
试试这个:
protected void change_attributes(object sender, EventArgs e)
{
var value = (sender as RadioButton).Attributes["value"];
}