模板列放在哪里都可以,没有什么只能放前面不能放后面的问题;修改时可以根据ItemIndex确定哪一行。
解决方案 »
- GridView如何导出字符型到Excel?
- 请教个简单的问题,很简单的,谢谢了。。。。。。。。
- 求助有关数据库更新的问题````
- 有关数据锁的问题
- ASP.NET WEB应用的导航问题
- 提问,一般租用的服务器里,用的access或sql server数据库设密码吗???
- ===========这个问题估计没人会回答了。。。。真是伤心。。。
- DataReader 对象查询数据,在刷新几十次之后数据库的连接池满了,怎么办?
- MVC3 kindeditor编辑器
- 关于showModalDialog在.cs中返回值如何赋给控件的问题!!! jonsonzxw(.net从入门到精通) 赶快进来呀
- 但用while语句后发现输出是空白?
- 单击模板列的button,如何获得该行是几行?
---当然可以放在后面,你调整布局就可以了
2.如果加上按钮以后,比如点击修改的Button,怎么能确定是这一行的Button呢?
---在ItemCommand事件里面可以根据e.Item.Cell来访问其他绑定的数据,当然包括ID
---模板列放在哪里都可以;对于你的问题用2个按钮列就可以 2.如果加上按钮以后,比如点击修改的Button,怎么能确定是这一行的Button呢?
---<asp:ButtonColumn Text="修改" CommandName="Modify"></asp:ButtonColumn>
<asp:ButtonColumn Text="删除2" CommandName="DeleteImage"></asp:ButtonColumn>
private void GridItem_ItemCommand(object source, DataGridCommandEventArgs e)
{
if(e.CommandName == "Modify")
…………………… if(e.CommandName == "DeleteImage")
………………}
{
if(e.CommandName == "Modify")
{
string tmp = e.Item.Cells[0].Text;//取该行第一列的值
…………
} if(e.CommandName == "DeleteImage")
………………}
<DataGrid ...... onItemCommand="GridItem_ItemCommand" ..../><columns>
<asp:templatecolumn>
<itemtemplate>
<asp:linkbutton commandname="change"....../>修改</asp:linkbutton>
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn>
<itemtemplate>
<asp:linkbutton commandname="delete"....../>删除</asp:linkbutton>
</itemtemplate>
</asp:templatecolumn>cs:
private void GridItem_ItemCommand(object source, DataGridCommandEventArgs e)
{
if(e.CommandName == "Modify")
…………………… if(e.CommandName == "DeleteImage")
………………}
{
if (e.CommandName=="Edit")//修改的摸板列
{
//执行你的修改代码
}
if (e.CommandName=="Delete")//删除摸板列
{
//执行你的删除代码
}
}
怎么调整布局?
grid是动态填充的。
好像不能将模板列放在最后吧?
基于模板的列在datagrid控件中扮演了一个很重要的角色,它们允许你增加任意一种类型的列到datagrid,datagrid通过纯文本的形式或者某种预定义的列类型显示内容。然而,有时预定义的列类型并不能实现我们想要的东西。模板列有四种不同的模板,如图1
Figure 1 DataGrid Column Templates
Name Description
ItemTemplate Contains the template for the items in a DataGrid's column.
<ItemTemplate>
<asp:label runat="server" text= '<%# ... %>'...>
</ItemTemplate>
You can use any combination of HTML text and ASP.NET controls to populate the column.
EditItemTemplate Controls the contents of the item selected for editing in the column of the DataGrid control. Place the controls you need for editing the cell between the opening and closing EditItemTemplate tags.
<EditItemTemplate>
<asp:textbox runat="server" text= '<%# ... %>'...>
</EditItemTemplate>
HeaderTemplate Contains the template for the heading section.
<HeaderTemplate>
<asp:label runat="server" text= "Header"...>
</HeaderTemplate>
If you omit this template, the column header is rendered with a label or a hyperlink if sorting is enabled. By specifying a custom template, you make yourself responsible to provide the user interface needed to enable sorting on the column.
FooterTemplate Contains the template for the footer section of the column. The default value is a null reference.
<FooterTemplate>
<asp:label runat="server" text= "..."...>
</FooterTemplate>
The footer is displayed only if the ShowFooter property of the DataGrid is set to True.你可能会频繁的使用模板列(ItemTemplate)。它定义了怎么样显示列中的单元格及由哪些元素组成控件的内容。HeaderTemplate 和 FooterTemplate我们就不说了,相信大家都知道是干什么用的。当列的所属行进入编辑模式时,EditItemTemplate属性指明单元格应该怎样变化。但要注意的是,它和datalist控件不一样,datagrid没有选中模板。
当你需要用不规范的方式显示整个列的时候,你的DataGrid应该用基于模板的列。如果你需要显示数据的数据无法用datagrid 提供的普通的模板显示时,这时,模板就是你的最佳选择了。
是个小小的遗憾!