pass a textbox value to a label inside a grid view on a button click in asp.net 4 and C#

回眸只為那壹抹淺笑 提交于 2019-12-12 02:16:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!