string strId = grdRow.Cells[0].Text; string memberId = grdRow.Cells[5].Text; 3/ 最终删除一条数据之前进行确认,这个可以使用摸版列,在摸版列中放置按钮控件,其中有一个客户端事件onclientclick,这里可以写确认处理javascript脚本.例如: <asp:TemplateField> <ItemTemplate> <asp:Button ID="btnRefuse" runat="server" OnClick="btnRefuse_Click" Text="拒绝" OnClientClick="return confirm(' 你真的要拒绝这个用户加入俱乐部?')"/> </ItemTemplate> </asp:TemplateField>ObjectDataSource In Depth
posted on 2005-12-22 23:06 自由、创新、研究、探索…… 阅读(6970) 评论(32) 编辑 收藏 引用 网摘 所属分类: DotNet 2.0
<script type="text/javascript"> // </script>Cells[x].Text取到值
回复 更多评论这几天在用这个控件做一些演示。发觉得这个控件似乎只是个半成品。或者说我对GridView还不习惯。。。。。。 1、无法绑定控记录。当GridView去绑定DataSet时,如果DataSet是空记录。则GridView连表头都不显示,感到很郁闷。。。。。。 2、绑定列对于时间的格式好像支持的有错误。 比如我有个时间字段datetime="2005-12-23 10:01:00" 当我的GridView使用绑定列,就无法设置格式。 <asp:BoundField DataField="datetime" DataFormatString="{0:HH:mm}" /> 这样,在列中,它还是显示:2005-12-23 10:01:00 如果我使用模板列,却是成功的。 <asp:TemplateField> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("datetime", "{0:HH:mm}") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> 这样,在列中,它显示:10:01 可用DataGrid却不会出此问题。。。。。。 回复 更多评论
如果要应用 formatstring ,必须将该列 Behavior-> HtmlEncode 设置为False,这个问题也困惑了我很久 :) 回复 更多评论
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { GridViewRow row = GridView1.SelectedRow; int id =Convert.ToInt32(GridView1.SelectedDataKey.Value); } 回复 更多评论
alex readed! 回复 更多评论
前面的同志说的时间格式的问题,我好像解决了。 加入以下代码就好。DataFormatString="{0:yyyy-MM-dd} 回复 更多评论
多谢了。困惑了 一个下午/ 回复 更多评论
把GridView绑定到DataSet,点击了Edit后出现更新和取消,却发现修改完数据后,更新按钮不响应,不知为什么?郁闷.。。。,请赐教! Email:swaterpig@gmail.com;Thanks! 回复 更多评论
Behavior-> HtmlEncode 我自己手动设置datasource 然后怎么设置HTMLENCODE? 回复 更多评论
@尖锐湿疣 可以在事件GridView1_RowCreated中进行处理 protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { DataControlField c = GridView1.Columns[2]; if (c is BoundField) { BoundField bf = (BoundField)c; bf.HtmlEncode = true; } } 回复 更多评论
http://www.thecodeproject.com/aspnet/GridViewRedux.asp http://www.thecodeproject.com/aspnet/addupdate.asp http://www.thecodeproject.com/aspnet/GridViewClientPostBack.asp http://www.thecodeproject.com/aspnet/GridViewConfirmDelete.asp 回复 更多评论
http://www.thecodeproject.com/aspnet/GridViewRadiobuttons.asp http://www.thecodeproject.com/aspnet/MasterDetail.asp http://www.thecodeproject.com/aspnet/CustomBusinessObjects.asp 回复 更多评论
Show Header/Footer of Gridview with Empty Data Source public void BuildNoRecords(GridView gridView, DataSet ds) { try { if (ds.Tables(0).Rows.Count == 0) { ds.Tables(0).Rows.Add(ds.Tables(0).NewRow()); gridView.DataSource = ds; gridView.DataBind(); int columnCount = gridView.Rows(0).Cells.Count; gridView.Rows(0).Cells.Clear(); gridView.Rows(0).Cells.Add(new TableCell()); gridView.Rows(0).Cells(0).ColumnSpan = columnCount; gridView.Rows(0).Cells(0).Text = "No Records Found."; } } catch (Exception ex) { } } 回复 更多评论
http://weblogs.asp.net/despos/archive/2005/06/30/416783.aspx 回复 更多评论
各位好。 我也在使用GRIDVIEW。 查了MSND也找了不少文章。 始终没办法找到其类似DATAGRID中 VirtualItemCount[获取或设置在使用自定义分页时 DataGrid 控件中的实际项数。] 各位的分页功能是怎么写的呢? 难道都读出整个表的数据么? 回复 更多评论
学习, 回复 更多评论
@感到郁闷 分页读取数据,用第3方的分页控件显示分页条,DATAGRID只显示当页数据. 回复 更多评论
DataFormatString的问题也是困扰了我很久,最终只好写了一个方法来格式化数据:public static void FormatNumericData (GridView grid, params string[] fieldNames) 对于负数,显示为红色 感觉GridView针对使用DataSourceID做了很多附加处理,对于使用DataSource,简直就是鸡肋 回复 更多评论
2/ 获取所选列的数据:DataGrid可以直接通过所选行来获取,GridView同样的代码无法运行。GridView 可以通过GridViewRow来获取。BtnAudit是模版列中的按钮。 GridViewRow grdRow = (GridViewRow)btnAudit.Parent.Parent; string strId = grdRow.Cells[0].Text; string memberId = grdRow.Cells[5].Text; 这段代码放到GridView的什么事件中? 我放到RowCommand()事件中根本就取不到,而且报的错误信息. 指点 回复 更多评论
http://209.171.52.99/useritems/TariqMultiHeaderGridview.asp http://209.171.52.99/useritems/PagingWithODS.asp 回复 更多评论
@RedVesper <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True" OnRowDataBound="GridView1_RowDataBound"> <Columns> <asp:BoundField DataField="Id" HeaderText="Id" /> <asp:BoundField DataField="name" HeaderText="俱乐部名称" /> <asp:BoundField DataField="username" HeaderText="用户姓名" /> <asp:BoundField DataField="city" HeaderText="所在城市" /> <asp:BoundField DataField="Company" HeaderText="服务的公司" /> <asp:BoundField DataField="memberid" HeaderText="用户ID" /> <asp:TemplateField ShowHeader="False"> <ItemTemplate> <asp:Button ID="btnAudit" runat="server" CausesValidation="false" OnClick= "btnAudit_Click" Text="同意" /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField> <ItemTemplate> <asp:Button ID="btnRefuse" runat="server" OnClick="btnRefuse_Click" Text="拒绝" OnClientClick="return confirm(' 你真的要拒绝这个用户加入俱乐部?')"/> </ItemTemplate> </asp:TemplateField> </Columns> <PagerSettings Mode="NumericFirstLast" Position="TopAndBottom" /> </asp:GridView> /// <summary> /// 拒绝成员注册审核 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnRefuse_Click(object sender, EventArgs e) { try { Button btnRefuse = (Button)sender; GridViewRow grdRow = (GridViewRow)btnRefuse.Parent.Parent; string strId = grdRow.Cells[0].Text; string memberId = grdRow.Cells[7].Text; ClubMemberManager.AuditClubMemberInfo(Convert.ToInt32(strId),memberId, -1); } catch (BusinessLayerException ex) { this.ProcessLogException(ex); } } 回复 更多评论
ASP.NET 2.0: Playing a bit with GridView "Sort Grouping" http://aspadvice.com/blogs/joteke/archive/2006/02/11/15130.aspx 回复 更多评论
如果没有设置模版列,我们将如何取得值 GridViewRow grdRow = (GridViewRow)btnRefuse.Parent.Parent; string strId = grdRow.Cells[0].Text; string memberId = grdRow.Cells[7].Text; 好像不能用,那该什么办。 指点 回复 更多评论
@zhang[匿名] 可以在RowCreated事件中赋予控件CommandArgument属性中保存当前行的ID,例如下面的处理方式 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { int index = Convert.ToInt32(e.CommandArgument); GridViewRow row = this.grvCompany.Rows[index]; string companyID = ((Label)row.Cells[0].FindControl("lblID")).Text; …… } protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { LinkButton lnbCompanyDetail = (LinkButton)e.Row.FindControl("lnbCompanyDetail"); LinkButton lnbLocations = (LinkButton)e.Row.FindControl("lnbLocations"); LinkButton lnbUsers = (LinkButton)e.Row.FindControl("lnbUsers"); lnbCompanyDetail.CommandArgument = e.Row.RowIndex.ToString(); lnbLocations.CommandArgument = e.Row.RowIndex.ToString(); lnbUsers.CommandArgument = e.Row.RowIndex.ToString(); } } 回复 更多评论
自由、创新、研究、探索…… 谢谢啦!!! 回复 更多评论
要在控件的编辑方法中再次绑定数据就好了 回复 更多评论
提个问题: 绑定了数据源的GridView1 想在某个字段内获取同个页面的一个session值。。 通过什么方法可以获得啊、还有想在模板行添加个 textbox 无法显示 <iframe src=user_index.aspx width="100%" height="100%" scrolling="no" frameborder="0"></iframe> 这种值。。 回复 更多评论
Formatting AutoGenerateColumns in an ASP.NET Grid http://www.codeproject.com/aspnet/FrmtAutoGenClmnASPNETGrid.asp 回复 更多评论
数据源如果直接设置在Gridview里,那就破坏了三层开发的结构,但是如果不绑定在里面,又没有办法设置列,这该怎么解决啊? 回复 更多评论
@young[匿名] objectdatasource控件,在.NET 2.0中,有了该控件,可以很方便地沟通表示层和逻辑层,而不会坏了三层开发的结构 李万宝的blog上有好几个ObjectDataSource控件的介绍http://www.cnblogs.com/mqingqing123/category/32262.html?Show=All 回复 更多评论
在第一条中如果直接写e.Row.Cells[5].Visible = false; 会出错 必须在下面两条语句中都写 if (e.Row.RowType == DataControlRowType.Header) { e.Row.Cells[3].Visible = false; } if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Cells[3].Visible = false; } 回复 更多评论
请教GridView中GridLines的颜色怎么设置呀?? 回复 更多评论
# re: GridView控件使用经验 2005-12-22 23:42 kasafuma