在数据集gridview中添加ItemTemplate字段

时间:2016-03-30 07:34:19

标签: asp.net sql-server vb.net

我有一个Gridview并且正在使用storedprocedure数据集进行此操作,我必须在数据集列的三列之后添加模板列。

<asp:GridView ID="gvProcessGrid" runat="server" BorderWidth="1px" CellPadding="4" Font-Names="Verdana"
                    Font-Size="8pt" Width="1910px" BorderStyle="None" GridLines="Horizontal" BackColor="White"
                    AllowSorting="True"  HorizontalAlign="Left">
                    <HeaderStyle BackColor="#7BA1C3" ForeColor="White" CssClass="lockHeadDivdgrid" HorizontalAlign="Left" />
                    <RowStyle CssClass="normtxt" />
                    <AlternatingRowStyle BackColor="White" CssClass="normtxt" />
                    <Columns>

                    <asp:TemplateField HeaderText="Notes">
                    <ItemTemplate>
                    <asp:TextBox runat="server" id="txtNotes" Width="90px" TextMode="MultiLine" />

                    </ItemTemplate>                        
                    </asp:TemplateField>
                    </Columns>
                </asp:GridView>


    Private Sub GridBind()

    Dim sqlCmd As SqlCommand = Nothing
    Dim myReader As SqlDataAdapter = New SqlDataAdapter
    Dim ds As New DataSet
    Dim myConnection As New SqlConnection(RecordManager.ConnectionString)

    Try


        sqlCmd = New SqlCommand("SP_ArticleInprocess_Report", myConnection)
        sqlCmd.CommandType = CommandType.StoredProcedure
        myConnection.Open()
        sqlCmd.Connection = myConnection
        sqlCmd.CommandTimeout = 500
        myReader = New SqlDataAdapter(sqlCmd)
        myReader.Fill(ds)

        gvProcessGrid.DataSource = ds
        gvProcessGrid.DataBind()
        ViewState("dtProcessgrid") = ds.Tables(0)

    Catch ex As Exception

    End Try

End Sub

建议我找到解决方案

提前致谢

1 个答案:

答案 0 :(得分:1)

您可以将gridview的autogeneratecolumns设置为false:

gvProcessGrid.AutogenerateColumns = false

然后在您的HTML中将<asp:BoundField/>添加到Gridview控件:

<Columns>
  <asp:BoundField HeaderText="Name of Column A" DataField="ColumnA" />
  <asp:BoundField HeaderText="Name of Column B" DataField="ColumnB" />
  <asp:BoundField HeaderText="Name of Column C" DataField="Columnc" />
   <ItemTemplate>
                    <asp:TextBox runat="server" id="txtNotes" Width="90px" TextMode="MultiLine" />

                    </ItemTemplate> 
</Columns>