asp.net - 如何使用 BoundFields 将 FooterTemplate 添加到 GridView

标签 asp.net gridview footer

祝您周末愉快。 终于我有了一些编辑/删除事件器来与 LINQ 支持一起工作。 我有一个添加记录事件,我知道它正在工作,但是在尝试了一部分之后,我不知道如何在页脚中添加一些文本框。

所以它是从页眉到页脚的一行,没有向右或向左移动。 有人可以帮助我吗!

enter image description here

我的代码是

    <asp:GridView ID="gdview"  runat="server" AutoGenerateColumns="False" DataKeyNames="test_id" OnRowCancelingEdit="gdview_RowCancelingEdit" OnRowDeleting="gdview_RowDeleting" OnRowEditing="gdview_RowEditing" OnRowUpdating="gdview_RowUpdating"
        BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal" ShowFooter="true">
        <Columns>
        <asp:BoundField HeaderText="Test CAT" DataField="test_cat">
            <ItemStyle Height="20px" Width="150px" />
        </asp:BoundField>
        <asp:BoundField HeaderText="Test INFO" DataField="test_info">
            <ItemStyle Height="20px" Width="150px" />
        </asp:BoundField>  
        <asp:BoundField HeaderText="Test NUMBER" DataField="test_number">
            <ItemStyle Height="20px" Width="150px" />
        </asp:BoundField>   
        <asp:BoundField HeaderText="Test DATE" DataField="test_datetime">
            <ItemStyle Height="20px" Width="150px" />
        </asp:BoundField>       
        <asp:CommandField ShowEditButton="True">
            <ItemStyle Width="100px" />
        </asp:CommandField>
        <asp:TemplateField>
        <ItemTemplate>
          <asp:LinkButton ID="lnkdel" runat="server" Text="Delete" CommandName="Delete"   OnClientClick="return confirm('Do you want to delete?')"></asp:LinkButton>      
        </ItemTemplate>
        <ItemStyle Width="100px" />
        </asp:TemplateField>

    </Columns>
    <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
    <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
    <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
    <SortedAscendingCellStyle BackColor="#F7F7F7" />
    <SortedAscendingHeaderStyle BackColor="#4B4B4B" />
    <SortedDescendingCellStyle BackColor="#E5E5E5" />
    <SortedDescendingHeaderStyle BackColor="#242121" />
    </asp:GridView>

好的,但是如何使用它,如果我使用模板,它如何知道从哪个单元格获取值!?

 Protected Sub gdview_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
    Using db As New ThedatabaseconnectionDataContext()
        Try
            'getting table
            Dim tbltest As Table(Of testtable) = db.GetTable(Of testtable)()
            'getting an exiting row
            Dim objtest As testtable = tbltest.SingleOrDefault(Function(p) p.test_id = Integer.Parse(gdview.DataKeys(e.RowIndex).Value.ToString()))
            If objtest IsNot Nothing Then
                'modifying the row
                objtest.test_cat = DirectCast(gdview.Rows(e.RowIndex).Cells(0).Controls(0), TextBox).Text
                objtest.test_info = DirectCast(gdview.Rows(e.RowIndex).Cells(1).Controls(0), TextBox).Text
                objtest.test_number = DirectCast(gdview.Rows(e.RowIndex).Cells(2).Controls(0), TextBox).Text
                objtest.test_datetime = DirectCast(gdview.Rows(e.RowIndex).Cells(3).Controls(0), TextBox).Text
                'saving rows added
                db.SubmitChanges()
                gdview.EditIndex = -1
                bindgrid()
                ' Me.lblMsg.Text = "Updated Successfully"
            Else
                'Me.lblMsg.Text = "Employee not found"
            End If
        Catch ex As Exception
            'Me.lblMsg.Text = ex.Message
        End Try
    End Using

最佳答案

你可以尝试使用

<columns>
  <asp:templatefield headertext="Test" >
    <itemtemplate>
       .... 
    </itemtemplate>
    <footertemplate>
      <asp:TextBox id="TestTbx"   runat="server"/>
    </footertemplate>
  </asp:templatefield>
</columns>

链接:http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.templatefield.footertemplate.aspx

关于asp.net - 如何使用 BoundFields 将 FooterTemplate 添加到 GridView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12545919/

相关文章:

android - GridView 的平滑滚动

asp.net - C# 如何在 GridView 上创建超链接 OnClick 事件?

asp.net - 遍历 GridView 中的所有行

javadoc - 将 "Last Modified"时间戳插入 javadoc 页脚

android webview - 中间的页脚?

Asp.net 将文本框 1 设置为等于文本框 2

c# - MVC3,从列表中获取更新的表单数据

c# - ASP.NET:通过 Intellisense 的 Page_Events 列表?我怎么知道签名?

c# - 在 AsyncFileUpload 上传完成时启用按钮

layout - 页面未满时,如何将脚注强制到页面的最底部?