<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<div align ="right">
<asp:ImageButton ID="ImageButton2" runat="server" Height="42px" ImageUrl="~/back.png" OnClick="ImageButton2_Click" />
<asp:ImageButton ID="ImageButton1" runat="server" Height="45px" ImageUrl="~/gnome-logout-icone-3872-128.png" OnClick="ImageButton1_Click" />
</div>
<div align="center">
<asp:Label ID="lb1" runat="server" Text="Label"></asp:Label>
<h1><font color="olive">User Details</font></h1>
<table border="1" style="border-collapse: collapse; width: 369px;" cellspacing="1">
<tr>
<td width="77" height="16" align="left" ><b><font size="2" color="red">Name:</font></b></td>
<td width="77" height="16" align="left" ><b><font size="2"> <asp:Label
ID="UserName" runat="server" Font-Bold="True"></asp:Label><br /></font></b></td>
<td width="77" height="16" align="left" ><b><font size="2" color="red">StaffCode:</font></b></td>
<td width="77" height="16" align="left" ><b><font size="2"> <asp:Label
ID="lbl_address" runat="server" Font-Bold="True"></asp:Label><br /></font></b></td>
<td width="77" height="16" align="left" ><b><font size="2" color="red">Branch:</font></b></td>
<td width="77" height="16" align="left" ><b><font size="2"> <asp:Label
ID="lbl_sal" runat="server" Font-Bold="True"></asp:Label><br /></font></b></td>
<td width="77" height="16" align="left" ><b><font size="2" color="red">Designation:</font></b></td>
<td width="77" height="16" align="left" ><b><font size="2"> <asp:Label
ID="lbl_phone" runat="server" Font-Bold="True"></asp:Label><br /></font></b></td>
</td>
</tr>
</table>
记录数量 :
<asp:TextBox ID="txtNo" runat="server"></asp:TextBox>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
<br />
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField HeaderText="Branch">
<ItemTemplate>
<asp:TextBox ID="txtBranch" runat="server" Height="18px" Width="72px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date">
<ItemTemplate>
<asp:TextBox ID="txtDate" Text="<%# System.DateTime.Now.ToString() %>" runat="server" Height="18px" Width="72px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="SrNo">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</Columns>
</asp:GridView>
//现在我无法做的是我想将一个标签值放入//gridview 的文本框中 标签(lbl_sal)向我显示了我想将其值放入//textbox(文本框 ID="分支名称")的分支。有什么办法吗
GridView
通常包含多行,这是此控件的唯一原因。因此,如果要为网格中的TextBox
分配单个值,则会令人困惑。
通常,您通过GridView
的DataSource
来控制输入。因此,如果您修改该值,则将该值放入网格中。
如果要在不修改数据源的情况下将该值分配给网格中的每一行,则可以使用 RowDataBound
:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TextBox txtBranch (TextBox)e.Row.FindControl("txtBranch");
txtBranch.Text = lbl_sal.Text;
}
}