大佬教程收集整理的这篇文章主要介绍了使用onrowdatabound从gridview asp.net c#中的隐藏单元格中获取值,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
如果你有一个像这样隐藏单元格的gridview
<asp:GridView ID="Timeevents" runat="server" OnRowDataBound="Timeevents_RowDataBound" OnRowCommand = "Timeevents_RowCommand" AutoGeneratecolumns="false"> <columns> <asp:BoundField datafield="CasEID" HeaderText="CasEID" Visible = "false" /> <asp:BoundField datafield="caseworkerID" HeaderText="CwID" Visible = "false" /> <asp:BoundField datafield="EventTypEID" HeaderText="EvTypEID" Visible = "false" /> <asp:BoundField datafield="CaseWorker" HeaderText="Case Worker" /> <asp:BoundField datafield="EventDate" HeaderText="Event Date" /> <asp:BoundField datafield="Code" HeaderText="Code" /> <asp:BoundField datafield="@R_216_10586@lUnits" HeaderText="@R_216_10586@l Units" /> <asp:BoundField datafield="EventType" HeaderText="Event Type" /> <asp:BoundField datafield="UnitCost" HeaderText="Unit Cost" /> <asp:BoundField datafield="@R_216_10586@lCost" HeaderText="@R_216_10586@l Cost"/> <asp:TemplateField HeaderText="ADD"> <ItemTemplate> <asp:Button ID="AddUnit" runat="server" Text=" +1 " CommandName="AddUnit" CommandArgument='<%# Eval("CasEID")+ ";" + Eval("CaseworkerID")+ ";" + Eval("EventDate")+ ";" + Eval("EventTypEID")+ ";" + ("1")%>'/> </ItemTemplate> </asp:TemplateField> </columns> </asp:GridView>
然后似乎不可能使用(e.Row.Cells [2] .Text)在onRowDatabound处理程序中获取这些值
我通过不将任何BoundFields设置为Visible =“false”解决了这个问题
所以它们是可见的=默认情况下为“true”.在后面的代码中获取onRowDatabound处理程序中所需的值,然后使它们不可见.像这样.
protected void Timeevents_RowDataBound(object sender,GridViewRowEventArgs E) { if (e.Row.RowType == DataControlRowType.Da@R_800_2301@w) { // just for the da@R_800_2301@ws int a = (int.Parse(e.Row.Cells[2].Text)); if (a % 2 == 0) { e.Row.BACkColor = System.Drawing.Color.Gainsboro; } else { e.Row.BACkColor = System.Drawing.Color.White; } } // end if so this applies to header and data rows e.Row.Cells[0].Visible = false; e.Row.Cells[1].Visible = false; e.Row.Cells[2].Visible = false; }
是一个相当绿色,它花了我很多的谷歌搜索围绕许多论坛和调试,以确定处理程序无法看到隐藏的数据绑定字段,我似乎无法找到如何基于隐藏字段设置rowcolour的答案所以我虽然id发布此内容供其他人查找
以上是大佬教程为你收集整理的使用onrowdatabound从gridview asp.net c#中的隐藏单元格中获取值全部内容,希望文章能够帮你解决使用onrowdatabound从gridview asp.net c#中的隐藏单元格中获取值所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。