asp.net – 如何将网页添加到gridview
发布时间:2020-05-28 16:50:34 所属栏目:asp.Net 来源:互联网
导读:我有一个有3列的网格 – 编辑,ID,电影.我想添加一个带有插入链接按钮的页脚,分别是2个文本框,但无法这样做.可能吗. ASPX: asp:GridView ID=gridview1 runat=server AutoGenerateColumns=False OnRowEditing=gridview1_RowEditing OnRowCancelingEdi
|
我有一个有3列的网格 – 编辑,ID,电影.我想添加一个带有插入链接按钮的页脚,分别是2个文本框,但无法这样做.可能吗. ASPX: <asp:GridView ID="gridview1" runat="server" AutoGenerateColumns="False"
OnRowEditing="gridview1_RowEditing"
OnRowCancelingEdit="gridview1_RowCancelingEdit"
ShowFooter="true" >
<Columns>
<asp:CommandField ShowEditButton="true" ShowDeleteButton="true" />
<asp:BoundField DataField="id" HeaderText="ID" />
<asp:BoundField DataField="movie" HeaderText="MOVIE" />
</Columns>
</asp:GridView>
当我尝试以下操作时,commandfield有一个错误,即不支持此元素. <Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CommandField ShowEditButton="true" ShowDeleteButton="true" />
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="lnkInsert" runat="server" Text="Insert"></asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
</columns>
另一种方法是使用itemTemplate&每个列控件的EditTemplate.但我发现这很简单,并希望以这种方式进行.那么我可以在这个结构中添加一个页脚. 解决方法对的,这是可能的.但这需要使用< FooterTemplate>在里面< TemplateField>.对每个列使用TemplateFields,并为每个列设置FooterTemplate.注意:ID列似乎是主键.因此,删除< FooterTemplate>来自相应的< TemplateField>如果ID是主键或数据库中的自动生成字段,则为ID列定义. 注2:< FooterTemplate>只需包含一个TextBox. <Columns>
<asp:TemplateField>
<EditItemTemplate>
<asp:LinkButton ID="lnkBtnUpdate" runat="server" CausesValidation="True"
CommandName="Update" Text="Update"></asp:LinkButton>
<asp:LinkButton ID="lnkBtnCancel" runat="server"
CausesValidation="False"
CommandName="Cancel" Text="Cancel">
</asp:LinkButton>
</EditItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="lnkBtnInsert" runat="server"
CommandName="Insert">Insert</asp:LinkButton>
</FooterTemplate>
<ItemTemplate>
<asp:LinkButton ID="lnkBtnEdit" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit"></asp:LinkButton>
<asp:LinkButton ID="lnkBtnDelete" runat="server"
CausesValidation="False"
CommandName="Delete" Text="Delete">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ID">
<EditItemTemplate>
<asp:TextBox ID="TextBoxID" runat="server" Text='<%# Bind("ID") %>'>
</asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("ID") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtID" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="MOVIE">
<EditItemTemplate>
<asp:TextBox ID="TextBoxMovie" runat="server" Text='<%# Bind("Movie") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtMovie" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Movie")%>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
现在有两种方法可以插入数据.您可以使用GridView OnRowCommand事件,也可以处理Insert按钮的OnClick事件. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 记一道毫无思路的算法题
- asp.net – 正在生成无效的Webresource.axd参数
- VS 2015.为ASP.NET 5 web项目设置正确的目标框架
- asp.net – LINQ查询,其中boolean值为true或false
- asp.net – web部署工具2.1和web部署3.5有什么区别?哪一个
- asp.net-mvc-3 – 我应该尝试使用MVC3和ASP.net的F#吗?
- .net – WinInet如何确定缓存的内容和时间?
- asp.net-mvc – 使用Angular VS Razor进行ASP.Net MVC验证
- asp.net-web-api – asp.net web api self hosting / owin
- asp.net-mvc – ASP.Net MVC 5带范围的Google身份验证
推荐文章
站长推荐
- asp.net-mvc – MvcContrib.MVC3-ci和Mvc.Contri
- 在经典ASP调试的Visual Studio 2012中禁用了应用
- asp.net-mvc-4 – 如何让你的MVC控制器DRY为Edit
- asp.net-mvc-3 – ASP.Net MVC 3 Razor Concaten
- 动态加载asp.net网站中的用户控件(ascx)
- asp.net – 在.aspx页面上显示图像的字节
- asp.net – 适用于多个用户的EWS通知中心
- asp.net-mvc – jQuery脚本包含在mvc 4模板的页面
- 在Azure网络应用程序中显示ASP.NET 5错误页面
- asp.net-mvc – 数据模型需要两个属性之一
热点阅读
