2014-03-19 59 views
1

我有一個問題,我想檢索單選按鈕選擇更改事件後端數據綁定字段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

你需要獲得值的所有行?爲什麼要循環?你不需要綁定到無線電引起回傳的價值? –

+0

實際上,我想檢索reg_id的值單選按鈕被檢查。不是全部。關於單選按鈕勾選更改 –

回答

3

試試這個:

protected void change_attributes(object sender, EventArgs e) 
{ 
    var value = (sender as RadioButton).Attributes["value"]; 
} 
+0

謝謝@Amir Abbas Sherafatian –