问题
I have 2 asp:panels. One asp:panel contains a textbox and button whose code is as follows
<asp:TextBox ID="tbGoal" runat="server" CssClass="textbox" Width="222px" Height="26px"></asp:TextBox><br />
<asp:Button ID="btnUpdate" runat="server" Text="Update Goal" CssClass="button" OnClick="btnUpdate_Click" />
/* ****************************************************************************
* CODE BEHIND
*
******************************************************************************** */
protected void btnUpdate_Click(object sender, EventArgs e)
{
// I am trying to pass the updated textbox value to a label which is inside a GridView
// which is inside the second ASP:PANEL
}
Can someone tell me if this is possible. Appreciate it
回答1:
First, Identify the row the label will be located.
second, determine if the label can be found FindControl
method of the grid views selected row.
Once the control has been found, set the value.
the following is only a sample and may not be exact.
Label l = (Label)gv.rows[0].FindControl["label"] //again determine the index.
if (l != null)
l.text = textbox.Text
Alternative:
Change the dataset that is binding to the Gridview rather than modifying the grids values. ultimately these values will most likely have to be saved/stored anyway so do it first.
来源:https://stackoverflow.com/questions/11552826/pass-a-textbox-value-to-a-label-inside-a-grid-view-on-a-button-click-in-asp-net