Asp.net 对象发送者属性值
我有一个问题,我想在单选按钮选择更改时检索后端数据绑定字段reg_id的值。请告诉我我做错了Asp.net 对象发送者属性值,asp.net,Asp.net,我有一个问题,我想在单选按钮选择更改时检索后端数据绑定字段reg_id的值。请告诉我我做错了 <asp:GridView ID="GridView1" runat="server" class="gridview" AutoGenerateColumns="False" DataKeyNames="reg_id" onrowcommand="GridView1_RowCommand"> <Columns> <asp:B
<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();
}
for(int i=0;i
试试这个:
protected void change_attributes(object sender, EventArgs e)
{
var value = (sender as RadioButton).Attributes["value"];
}
您需要获取所有行的值吗?为什么是循环?您不需要已绑定到单选按钮的值来导致回发?实际上,我希望在选中单选按钮的位置检索注册表id的值。不是全部。在单选按钮事件中选中ChangeThank@Amir Abbas Sherafatian