前台的话应该是:<asp:CommandField ShowDeleteButton="True" HeaderText="删除" ></asp:CommandField> //放在最后面就行了</Columns>后台的话: For i = 0 To gridview1.rows.Count - 1 gridview1.rows(i).Cells(gridview1.Columns.Count - 1).Attributes.Add("onclick", "javascript: this.parentNode.style.backgroundColor='#eeeeee'; if (confirm('Are you sure to delete this record?')){return;}else{this.parentNode.style.backgroundColor='Ivory';return false;};") Next 代码可以放在 gridview1.databind()之后没有测试过啊,我在用DATAGRID....
if (!IsPostBack) { TemplateField tField; // Create the dynamic templates tField = new TemplateField(); tField.ItemTemplate = new GridViewTextTemplate(DataControlRowType.DataRow, "parameter_description", "textParameterDesc"); tField.HeaderTemplate = new GridViewTextTemplate(DataControlRowType.Header, "说明", "textParameterDescHd"); // Add the dynamic templates field column to the GridView GridView1.Columns.Add(tField); }
或
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete" OnClientClick="return confirm('确认要删除吗?');"
Text="删除"> </asp:LinkButton>
</ItemTemplate>
For i = 0 To gridview1.rows.Count - 1
gridview1.rows(i).Cells(gridview1.Columns.Count - 1).Attributes.Add("onclick", "javascript: this.parentNode.style.backgroundColor='#eeeeee'; if (confirm('Are you sure to delete this record?')){return;}else{this.parentNode.style.backgroundColor='Ivory';return false;};")
Next
代码可以放在 gridview1.databind()之后没有测试过啊,我在用DATAGRID....
谢谢大家的回答
位置的话最后的.ADD方法里有定位?
不给我分我就要哭啦
父页面不刷新 额貌似我还没看到AJAX 哈哈我也是菜菜鸟。。你找AJAX的看看
不过这个COMMANDFIELD的效果和前台一样的啊,点击这个会自动的把这一行的换成EDITITEM下的东西显示出来,应该可以满足你的效果2.在服务器进行数据库操作,那是必须的啦。。在由于你按钮设置的是类型不一样,可能是EDIT可能是DELETE,会有相应的点击触发事件,在里面写就行了,,相应的话刚不是定位行了么,再加一CELL[I],就定位到某个单元格数据了事件关联你不会的写的话,在前台拖个EDIT 按钮,然后查看到GRIDVIEW的属性,左键双击相应事件会有代码你参考完
现在我如果用代码在服务器端向GridView中增加HyperLinkField,HyperLinkField也是能在数据绑定之前才有用(但此时HyperLinkField还是在表的第1行),在数据绑定之后,如果再向表中增加HyperLinkField,就不能增加了。
这个问题已经弄了我好长时间都不能解决,希望大家帮忙。
所谓的不在最后神奇。
if (!IsPostBack)
{
gridview1.datasource=ds;
gridview1.columns.insert(locate,COMMANDFIELD);
gridview1.bind();
}
这里的locate你应该是由你的SQL或者说DS(ds.rows.count-1)加上你的是否要填的东西,联合起来决定