我如何将值从文本框传递到gridview中的标签 [英] How can i pass the value from text box to label in gridview

查看:55
本文介绍了我如何将值从文本框传递到gridview中的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将值从文本框传递到gridview中的标签

How can i pass the value from text box to label in gridview

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"

                   ForeColor="#333333" GridLines="None" ShowFooter="True"

                   onselectedindexchanged="GridView1_SelectedIndexChanged"

                   onrowcommand="GridView1_RowCommand" >
                   <RowStyle BackColor="#EFF3FB" />
                   <Columns>
                       <asp:TemplateField  HeaderText="NAME">
                       <ItemTemplate>
                               <asp:TextBox ID="txtName" runat="server" Visible ="true" ></asp:TextBox>
                               <asp:Label ID="lblName" visible = "false"  runat="server"></asp:Label>

                       </ItemTemplate>

                       </asp:TemplateField>
                        <asp:TemplateField  HeaderText="AGE">
                       <ItemTemplate>
                               <asp:TextBox ID="txtAge" runat="server" Visible ="true" ></asp:TextBox>
                               <asp:Label ID="lblAge" visible = "false" runat="server"></asp:Label>

                       </ItemTemplate>

                       </asp:TemplateField>
                        <asp:TemplateField  HeaderText="Qualification">
                       <ItemTemplate>
                               <asp:TextBox ID="txtQual" runat="server" Visible ="true" ></asp:TextBox>
                               <asp:Label ID="lblQual" visible = "false" runat="server"></asp:Label>

                       </ItemTemplate>

                       </asp:TemplateField>
                        <asp:TemplateField  HeaderText="Experience">
                       <ItemTemplate>
                               <asp:TextBox ID="txtExp" runat="server" Visible ="true" ></asp:TextBox>
                               <asp:Label ID="lblExp" visible = "false" runat="server"></asp:Label>

                       </ItemTemplate>

                       </asp:TemplateField>
                       <asp:ButtonField HeaderText = "Add" text = "Add" CommandName = "Add"  ButtonType="Button" />

                         <%-- <EditItemTemplate>
                               <asp:TextBox ID="txtName" runat="server" Visible ="true" ></asp:TextBox>
                               <asp:Label ID="lblName" visible = "false" runat="server"></asp:Label>
                           </EditItemTemplate>--%>
                       <%--<asp:BoundField HeaderText="NAME" />
           <asp:BoundField HeaderText="AGE" />
           <asp:BoundField HeaderText="Qualification" />
           <asp:BoundField HeaderText="Experience" />
           <asp:BoundField />
           <asp:BoundField HeaderText="Add" />--%>
                   </Columns>
                   <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                   <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                   <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                   <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                   <EditRowStyle BackColor="#2461BF" />
                   <AlternatingRowStyle BackColor="White" />
               </asp:GridView>

推荐答案


试试这个

Hi ,
Try this

protected void Button1_Click(object sender, EventArgs e)
   {
       foreach (GridViewRow row  in GridView1.Rows)
       {
           if ((Label)row.FindControl("lbl") is Label)
           {
               ((Label) row.FindControl("lbl")).Text = txtname.Text;
           }
       }

   }




Or

protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
//for specific row
    ((Label) GridView1.Rows[e.NewSelectedIndex].FindControl("lbl")).Text = txtname.Text;
}


最好的问候
M.Mitwalli


Best Regards
M.Mitwalli



U可以使用行数据绑定事件来执行此操作,它将在绑定每一行时触发.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx [
Hi,
U can do this using row databound event it will fire on binding every row.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx[^]

Best Luck
Happy Coding


当您希望在绑定时或单击行时将文本框的值传递给标签时,请提供我

如果要在绑定时传递值,则可以将数据库"参数分配给文本"框,也可以标记相同的字段.

或者您可以在绑定时使用Grid View的行绑定事件分配值.


谢谢
阿尼尔·阿夫哈德
(印度)
Please Provide me when you want to pass value of text box to label at a time of binding or at a time on click on row

if you want to Pass value at at a time of binding then you can Assign DB parameter to Text box as well as label same field.

or you can assign value at atime of Binding use Row bound Event of Grid View.


thanks
Anil Avhad
(India)


这篇关于我如何将值从文本框传递到gridview中的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆