C# GridView外部的控件发生回发后,如何更新GridView?

C# GridView外部的控件发生回发后,如何更新GridView?,c#,asp.net,gridview,postback,C#,Asp.net,Gridview,Postback,我有一个GridView,当用户单击此GridView外的按钮时,将对其进行更新,应为特定行更新一个GridView列。 因此,我正在为PostBack中的GridView投标新数据。但是我们知道,PostBack是在OnClick按钮事件之前调用的。因此,GridView此时被绑定。但是我希望根据OnClick按钮事件中的某些操作,为特定行更新GridView列值。 因此,我还尝试在OnClick按钮事件中绑定GridView。但它没有得到更新。 所以我主要的怀疑是 这是否可以在导致回发的Cl

我有一个
GridView
,当用户单击此
GridView
外的按钮时,将对其进行更新,应为特定行更新一个
GridView
列。 因此,我正在为
PostBack
中的
GridView
投标新数据。但是我们知道,
PostBack
是在
OnClick
按钮事件之前调用的。因此,
GridView
此时被绑定。但是我希望根据
OnClick
按钮事件中的某些操作,为特定行更新
GridView
列值。 因此,我还尝试在
OnClick
按钮事件中绑定
GridView
。但它没有得到更新。 所以我主要的怀疑是

这是否可以在导致
回发的Click事件的
PostBack
块中调用的方法中传递值

private void bindTheGriView()
    {
        DataTable dt = new DataTable();
        DataRow dr = null;
        dt.Columns.Add(new DataColumn("Row Number", typeof(string)));
        dt.Columns.Add(new DataColumn("POS Id", typeof(string)));
        dt.Columns.Add(new DataColumn("Action", typeof(string)));
        dt.Columns.Add(new DataColumn("Status", typeof(string)));
        for (int index = 0; index < m_listStrPendingListOfPOS.Count; index++)
        {
            dr = dt.NewRow();
            int iRowNo = index + 1;
            dr["Row Number"] = iRowNo;
            string strGridViewPOSId = m_listStrPendingListOfPOS[index];
            dr["POS Id"] = strGridViewPOSId;
            dr["Action"] = string.Empty;
            //check for the flag. if the flag is true set status to Pending else to Associated
            dr["Status"]=((Label)GridViewMultiplePOSAssociationId.Rows[index].FindControl("LabelStatusPendingPOSId")).Text;
           dt.Rows.Add(dr);
        }

        ViewState["POSTable"] = dt;
        GridViewMultiplePOSAssociationId.DataSource = dt;
        GridViewMultiplePOSAssociationId.DataBind();
    }


    protected void btnSave_Click(object sender, EventArgs e)
{
    bool statusFlag=false;
    if (ViewState["RowIndexPOS"] != null)
    {
        int iRowIndex = Convert.ToInt32(ViewState["RowIndexPOS"]);
        Label lblStatus = (Label)GridViewMultiplePOSAssociationId.Rows[iRowIndex].FindControl("LabelStatusPendingPOSId");
        //Means all rows in GridView are successfully associated
        if (table.Rows.Count == iResultCount)
        {
            lblStatus.Text = "Associated";
        }
        else
        {
            lblStatus.Text = "Pending";
        }
    }
    //now call the binding method with the bool flag value
     bindTheGriView();
}
private void bindTheGriView()
{
DataTable dt=新的DataTable();
数据行dr=null;
添加(新的数据列(“行号”,typeof(字符串));
添加(新的数据列(“POS Id”,typeof(string));
Add(新数据列(“操作”,typeof(字符串));
添加(新的数据列(“状态”,类型(字符串));
for(int index=0;index

不,我没有使用更新面板。

不要在回发中使用。将数据抽象绑定到一个方法中,并从适当的事件中调用该方法

public void BindMyData()
{
    // Do data bindings on all bound controls
}

public void Page_Load(object sender, EventArgs e) 
{
    if (!IsPostBack)
        BindMyData();
}

public void myClick(object sender, EventArgs e)
{
    // Update the data in the repository


    BindMyData();
}

或者,您可以将数据绑定移动到
页面\u PreRender
事件,以确保它在任何控件动作后始终绑定。

您可以显示gridview和按钮单击事件的一些代码吗?发布一些代码并告诉我们您是否可以使用UpdatePanels。答案将取决于UpdatePanel是否是一个选项。已修改问题。