如何使用BoundFields将FooterTemplate添加到GridView中 [英] How do I add FooterTemplate to GridView with BoundFields
问题描述
终于,我得到了一些编辑/删除工作,以支持LINQ。
我有一个添加记录事件,我知道正在工作,但在尝试了一部分之后,我不知道如何在脚注中添加一些文本框。
所以这是一个从页眉到页脚的行,没有向右或向左移动。
有些人可以帮助我!
我的代码是
< asp:GridView ID =gdviewrunat = serverAutoGenerateColumns =FalseDataKeyNames =test_idOnRowCancelingEdit =gdview_RowCancelingEditOnRowDeleting =gdview_RowDeletingOnRowEditing =gdview_RowEditingOnRowUpdating =gdview_RowUpdating
BackColor =WhiteBorderColor =#CCCCCCBorderStyle = NoneBorderWidth =1pxCellPadding =4ForeColor =BlackGridLines =HorizontalShowFooter =true>
<列>
< asp:BoundField HeaderText =Test CATDataField =test_cat>
< ItemStyle Height =20pxWidth =150px/>
< / asp:BoundField>
< asp:BoundField HeaderText =Test INFODataField =test_info>
< ItemStyle Height =20pxWidth =150px/>
< / asp:BoundField>
< asp:BoundField HeaderText =Test NUMBERDataField =test_number>
< ItemStyle Height =20pxWidth =150px/>
< / asp:BoundField>
< asp:BoundField HeaderText =Test DATEDataField =test_datetime>
< ItemStyle Height =20pxWidth =150px/>
< / asp:BoundField>
< asp:CommandField ShowEditButton =True>
< ItemStyle Width =100px/>
< / asp:CommandField>
< asp:TemplateField>
< ItemTemplate>
< asp:LinkButton ID =lnkdelrunat =serverText =DeleteCommandName =DeleteOnClientClick =return confirm('您要删除吗?')>< ASP:LinkButton的>
< / ItemTemplate>
< ItemStyle Width =100px/>
< / asp:TemplateField>
< /列>
< FooterStyle BackColor =#CCCC99ForeColor =Black/>
< HeaderStyle BackColor =#333333Font-Bold =TrueForeColor =White/>
< SelectedRowStyle BackColor =#CC3333Font-Bold =TrueForeColor =White/>
< SortedAscendingCellStyle BackColor =#F7F7F7/>
< SortedAscendingHeaderStyle BackColor =#4B4B4B/>
< SortedDescendingCellStyle BackColor =#E5E5E5/>
< SortedDescendingHeaderStyle BackColor =#242121/>
< / asp:GridView>
好的但是如何使用这个工作,如果我使用模板,它怎么知道要获取什么单元格
prerotected Sub gdview_RowUpdating(ByVal sender As Object,ByVal e As GridViewUpdateEventArgs)
使用db As新的ThedatabaseconnectionDataContext()
尝试
'获取表
Dim tbltest As Table(Of testtable)= db.GetTable(Of testtable)()
'获得一个退出行
Dim objtest As testtable = tbltest.SingleOrDefault(Function(p)p.test_id = Integer.Parse(gdview.DataKeys(e.RowIndex).Value.ToString()))
如果objtest IsNot Nothing Then
'修改行
objtest.test_cat = DirectCast(gdview.Rows(e.RowIndex).Cells(0).Controls(0),TextBox).Text
objtest.test_info = DirectCast(gdview。行(e.RowIndex).Cells(1).Controls(0),TextBox).Text
objtest.test_number = D irectCast(gdview.Rows(e.RowIndex).Cells(2).Controls(0),TextBox).Text
objtest.test_datetime = DirectCast(gdview.Rows(e.RowIndex).Cells(3).Controls (0),TextBox).Text
'save rows added
db.SubmitChanges()
gdview.EditIndex = -1
bindgrid()
'Me.lblMsg .Text =更新成功
Else
'Me.lblMsg.Text =未找到员工
结束如果
赶上前例外
'Me.lblMsg .Text = ex.Message
结束尝试
结束使用
< columns>
< asp:templatefield headertext =Test>
< itemtemplate>
....
< / itemtemplate>
< footertemplate>
< asp:TextBox id =TestTbxrunat =server/>
< / footertemplate>
< / asp:templatefield>
< / columns>
链接: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.templatefield.footertemplate.aspx
Hope you have a good weekend. At long last I have got some editing/delete eventer to work with LINQ support. I have an Add record event which I know is working, but after trying a part, I do not know how I am adding some textbox's in my footer.
So it is a row from header and down to footer, without the move to the right or the left. Can some help me !?
My code is
<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>
Ok but how with this then work, if i use templates, how do it know what cell to get values from !??
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
You can try with
<columns>
<asp:templatefield headertext="Test" >
<itemtemplate>
....
</itemtemplate>
<footertemplate>
<asp:TextBox id="TestTbx" runat="server"/>
</footertemplate>
</asp:templatefield>
</columns>
Link : http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.templatefield.footertemplate.aspx
这篇关于如何使用BoundFields将FooterTemplate添加到GridView中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!