2015-03-13 44 views
-1
<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">&nbsp;<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">&nbsp;<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">&nbsp;<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">&nbsp;<asp:Label 
      ID="lbl_phone" runat="server" Font-Bold="True"></asp:Label><br /></font></b></td> 
    </td> 
    </tr> 
</table> 


無記錄:將標籤值轉換成databounded gridview的

<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中的文本框label(lbl_sal)向我顯示我想將其值放入// textbox(TextBox ID =「BranchName」)的分支。有沒有辦法

+0

沒有文本框'BranchName' – 2015-03-13 09:28:44

+0

是您的GridView顯示正確地textBox中?有沒有'數據源'它? – zey 2015-03-13 09:29:32

+0

@TimSchmelter,我認爲它是'txtBranch' :) – zey 2015-03-13 09:29:58

回答

0

A GridView通常包含多行,這是這種控制的唯一原因。出於這個原因,如果你想爲網格中的TextBox分配一個單獨的值,那就很讓人困惑。

通常,您可以通過GridViewDataSource控制輸入。所以如果你修改,你會得到這個值到網格中。

如果你想分配一個值到網格中的每一行,而無需修改,你可以使用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; 
    } 
} 
+0

其實我想用標籤的值填充textBranch的所有行,我使用了這個源,但問題是它不接受(e.Row.RowType)。你能告訴我爲什麼是這個問題@Tim Schmelter – 2015-03-16 05:56:28

+0

你會得到什麼例外,以及在哪條線上? – 2015-03-16 06:17:06

+0

說明:編譯服務此請求所需的資源時發生錯誤。請查看以下具體的錯誤細節並適當修改您的源代碼。 編譯器錯誤消息:CS1528:預期;或=(不能在聲明中指定構造函數參數) – 2015-03-17 04:41:49