2014-01-16 60 views
-1

我想創建一個模板字段一個GridView空GridView和我想要設置單元格爲空,我想將它們顯示在頁面中。布我成功地創建了模板字段,但將單元格初始化爲空不起作用。請幫我解決這個問題。謝謝。如何創建模板字段一個GridView,我想顯示在執行

這是GridView的HTML代碼:

 <asp:GridView ID="grdReqDetails" runat="server" AutoGenerateColumns="False"> 
       <Columns> 
        <asp:TemplateField HeaderText="S.No"> 
         <ItemTemplate> 
          <asp:TextBox ID="txtSNo" runat="server"></asp:TextBox> 
         </ItemTemplate> 
        </asp:TemplateField> 
        <asp:TemplateField HeaderText="Designation"> 
         <ItemTemplate> 
          <asp:TextBox ID="txtDesig" runat="server"></asp:TextBox> 
         </ItemTemplate> 
        </asp:TemplateField> 
        <asp:TemplateField HeaderText="Skill Set"> 
         <ItemTemplate> 
          <asp:TextBox ID="txtSkillSet" runat="server"></asp:TextBox> 
         </ItemTemplate> 
        </asp:TemplateField> 
        <asp:TemplateField HeaderText="Experience"> 
         <ItemTemplate> 
          <asp:TextBox ID="txtExp" runat="server"></asp:TextBox> 
         </ItemTemplate> 
        </asp:TemplateField> 
        <asp:TemplateField HeaderText="Num of Candidates"> 
         <ItemTemplate> 
          <asp:TextBox ID="txtNum" runat="server"></asp:TextBox> 
         </ItemTemplate> 
        </asp:TemplateField> 
       </Columns> 
      </asp:GridView> 

而後面的代碼:

 grdReqDetails.Rows[0].Cells[0].Text = ""; 
     grdReqDetails.Rows[0].Cells[1].Text = ""; 
     grdReqDetails.Rows[0].Cells[2].Text = ""; 
     grdReqDetails.Rows[0].Cells[3].Text = ""; 
     grdReqDetails.Rows[0].Cells[4].Text = ""; 
+0

我試過了,但我沒有辦法將單元格的初始值設置爲null。 – Aneez

回答

1
protected void DisGridBind() 
    { 

     DataTable Dt = new DataTable(); 
     DataRow Dr; 
     Dt.Columns.Add("Col1"); 
     Dt.Columns.Add("Col2"); 
     Dt.Columns.Add("Col3"); 
     Dt.Columns.Add("Col4"); 
     Dr = Dt.NewRow(); 
     Dt.Rows.Add(Dr); 
     gv_discpoint.DataSource = Dt; 
     gv_discpoint.DataBind(); 
     } 
+0

我已經有行作爲模板字段,但我希望這些行得到顯示。 – Aneez

+0

這是一種在gridview中添加空行的方法 – SK2185

0

對於初始爲空的GridView,你應該使用EmptyDataTemplate象下面這樣:

<asp:GridView ID="grdReqDetails" runat="server" AutoGenerateColumns="true">    
    <EmptyDataTemplate> 
     <asp:Label ID="Label1" runat="server" Text="S.No"></asp:Label> 
     <asp:TextBox ID="txtSNo" runat="server"></asp:TextBox><br /> 
     <asp:Label ID="Label2" runat="server" Text="Designation"></asp:Label> 
     <asp:TextBox ID="txtDesig" runat="server"></asp:TextBox><br /> 
     <asp:Label ID="Label3" runat="server" Text="Skill Set"></asp:Label> 
     <asp:TextBox ID="txtSkillSet" runat="server"></asp:TextBox><br /> 
     <asp:Label ID="Label4" runat="server" Text="Experience"></asp:Label> 
     <asp:TextBox ID="txtExp" runat="server"></asp:TextBox><br /> 
     <asp:Label ID="Label5" runat="server" Text="Num of Candidates"></asp:Label> 
     <asp:TextBox ID="txtNum" runat="server"></asp:TextBox> 
    </EmptyDataTemplate> 
    <Columns> 
     <asp:TemplateField HeaderText="S.No"> 
      <ItemTemplate> 
       <asp:TextBox ID="txtSNo" runat="server"></asp:TextBox> 
      </ItemTemplate> 
     </asp:TemplateField> 
     <asp:TemplateField HeaderText="Designation"> 
      <ItemTemplate> 
       <asp:TextBox ID="txtDesig" runat="server"></asp:TextBox> 
      </ItemTemplate> 
     </asp:TemplateField> 
     <asp:TemplateField HeaderText="Skill Set"> 
      <ItemTemplate> 
       <asp:TextBox ID="txtSkillSet" runat="server"></asp:TextBox> 
      </ItemTemplate> 
     </asp:TemplateField> 
     <asp:TemplateField HeaderText="Experience"> 
      <ItemTemplate> 
       <asp:TextBox ID="txtExp" runat="server"></asp:TextBox> 
      </ItemTemplate> 
     </asp:TemplateField> 
     <asp:TemplateField HeaderText="Num of Candidates"> 
      <ItemTemplate> 
       <asp:TextBox ID="txtNum" runat="server"></asp:TextBox> 
      </ItemTemplate> 
     </asp:TemplateField> 
    </Columns> 
</asp:GridView> 
相關問題