服务器端获取gridview中的
时间:2011-05-19 来源:fc5110
前台:
<asp:GridView ID="gridViewListNew" runat="server" AutoGenerateColumns="False" AllowSorting="True"
OnSorting="GridViewListSorting" DataKeyNames="FamiliesID" Visible="false" OnRowDataBound="GridViewNew_RowDataBound"
ClientIDMode="Static" CssClass="jqGrid">
<Columns>
<asp:TemplateField HeaderText="选择">
<ItemTemplate>
<asp:HiddenField ID="hdfCountieID" runat="server" Value='<%#Eval("CountieID") %>' />
<asp:HiddenField ID="hdfTownShipID" runat="server" Value='<%#Eval("TownShipID") %>' />
<asp:HiddenField ID="hdfVillageID" runat="server" Value='<%#Eval("VillageID") %>' />
<asp:HiddenField ID="hdfGroupID" runat="server" Value='<%#Eval("GroupID") %>' />
<asp:RadioButton ID="rbFamily" AutoPostBack="true" OnCheckedChanged="rbFamily_CheckedChanged"
runat="server" />
</ItemTemplate>
<HeaderStyle CssClass="alignCenter" Width="50px" />
</asp:TemplateField>
<Columns>
</asp:GridView>
后台更改事件:
/// <summary>
/// GridView_RedioButton单选事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void rbFamily_CheckedChanged(object sender, EventArgs e)
{
RadioButton rdo = (RadioButton)sender;
TableCell cell = (TableCell)rdo.Parent;
GridViewRow gridrow = (GridViewRow)cell.Parent;
for (int i = 0; i < gridViewListNew.Rows.Count; i++)
{
if (i != gridrow.RowIndex)
{
RadioButton rbt = gridViewListNew.Rows[i].FindControl("rbFamily") as RadioButton;
rbt.Checked = false;
}
}
}
后台获取事件:
for (int i = 0; i <= gridViewListNew.Rows.Count - 1; i++)
{
RadioButton rb = (RadioButton)gridViewListNew.Rows[i].FindControl("rbFamily");
if (rb.Checked == true)
{
hfNewFamilyPrimayKeyId.Value = "";
hfNewFamilyPrimayKeyId.Value = gridViewListNew.DataKeys[i].Value.ToString();
}
}