C# 单击按钮时在HiddenField中存储BoundField值

C# 单击按钮时在HiddenField中存储BoundField值,c#,asp.net,gridview,boundfield,hiddenfield,C#,Asp.net,Gridview,Boundfield,Hiddenfield,将HiddenField的值设置为GridView项值时遇到问题。我想做的是在GridView中获取BoundField(在本例中为“FIPSCountyCode”)的值,并在用户单击按钮(在本例中为“btnEdit”)对网格中的条目进行更改时将其存储在HiddenField中。我以前没用过HiddenFields,所以我忘了在这里做什么 HiddenField的设置如下: <asp:HiddenField ID="hdnFIPS" Value='<%#Eval("FIPSCoun

将HiddenField的值设置为GridView项值时遇到问题。我想做的是在GridView中获取BoundField(在本例中为“FIPSCountyCode”)的值,并在用户单击按钮(在本例中为“btnEdit”)对网格中的条目进行更改时将其存储在HiddenField中。我以前没用过HiddenFields,所以我忘了在这里做什么

HiddenField的设置如下:

<asp:HiddenField ID="hdnFIPS"  Value='<%#Eval("FIPSCountyCode")%>' runat="server" />

这一定是一个很愚蠢的问题,但我真的不知道如何继续。任何帮助都会很好

您可以通过以下方式从边界字段获取
FIPSCountyCode
的值:

protected void EditInfo(object sender, System.EventArgs e)
{
    if (Page.IsValid)
    {
        GridViewRow gvr = ((ImageButton)sender).NamingContainer as GridViewRow;
        hdnFIPS.Value = gvr.Cells[0].Text;

        redirectString = "~/Admin/Taxes/AddEditCountyInfo.aspx?FIPSCountyCode=" + hdnFIPS.Value;
        Response.Redirect(redirectString);
    }
}

是否
hdnFIPS
CountyList
之外?是的,它在CountryList之外。
public partial class Admin_County_Info : CommerceBuilder.UI.AbleCommerceAdminPage
{
    private string redirectString = String.Empty;

    protected void Page_Load(object sender, System.EventArgs e)
    {
        if (!Page.IsPostBack)
            PopulateCountyGrid();
    }

    protected void PopulateCountyGrid()
    {
        try
        {
            System.Data.SqlClient.SqlDataReader dr = null;
            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["AbleCommerce"].ToString()))
            {
                SqlCommand cmd = new SqlCommand("SELECT [FIPSCountyCode], [StateCode], [CountyName], [TaxRate] FROM [baird_InfoCounty]", cn);
                cmd.CommandType = CommandType.Text;
                cn.Open();
                dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                CountyList.DataSource = dr;
                CountyList.DataBind();
            }
        }
        catch (Exception eX)
        {

        }
    }

    #region Clicks and Event Handlers

    protected void EditInfo(object sender, System.EventArgs e)
    {
        if (Page.IsValid)
        {

            redirectString = "~/Admin/Taxes/AddEditCountyInfo.aspx?FIPSCountyCode=" + hdnFIPS.Value;
            Response.Redirect(redirectString);
        }

    }

    protected void AddInfo(object sender, System.EventArgs e)
    {
        if (Page.IsValid)
        {

            Response.Redirect("~/Admin/Taxes/AddEditCountyInfo.aspx");
        }

    }
}
protected void EditInfo(object sender, System.EventArgs e)
{
    if (Page.IsValid)
    {
        GridViewRow gvr = ((ImageButton)sender).NamingContainer as GridViewRow;
        hdnFIPS.Value = gvr.Cells[0].Text;

        redirectString = "~/Admin/Taxes/AddEditCountyInfo.aspx?FIPSCountyCode=" + hdnFIPS.Value;
        Response.Redirect(redirectString);
    }
}