如何获取DataList内GridView某行的数据
DataList嵌套了GridView,DataList的每一个Ietm里,都有一个GridView,我在DataList的ItemDataBound事件里写代码,需要做...
DataList嵌套了GridView,DataList的每一个Ietm里,都有一个GridView,我在DataList的ItemDataBound事件里写代码,需要做条件判断 protected void dltA1_ItemDataBound(object sender, DataListItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { DataTable dt2 = new DataTable(); dt2 = adoDB.DS.Tables[0].Clone(); GridView gvList1 = (GridView)e.Item.FindControl("gdvA2"); foreach (DataRow row in adoDB.DS.Tables[0].Rows) { if ((Int32)row[5] == 3 ) { dt2.Rows.Add(row.ItemArray); } } if (e.Item.ItemType == ListItemType.Item) { gvList1.DataSource = dt2.DefaultView; gvList1.DataBind(); } } } 在判断row[5] == 3的同时,还需要判断row[6]是不是小于该Item内GridView第一列绑定的数据,请问我如何获取到这个数据并做判断呢?
展开
1个回答
展开全部
最简单的就是使用模板列
参照:<asp:GridView ID="GridView1" Width="100%" runat="server" HorizontalAlign="Center" CellPadding="2" AutoGenerateColumns="False" DataKeyNames="InfoCode" PageSize="4" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing" OnRowDataBound="GridView1_RowDataBound">
<RowStyle CssClass="DataListBK1" />
<AlternatingRowStyle CssClass="DataListBK2" />
<HeaderStyle CssClass="DataListTitle" />
<Columns>
<asp:TemplateField HeaderText="选择" >
<ItemTemplate>
<asp:CheckBox ID="chkChecked" runat="server" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Wrap="false"/>
<HeaderStyle Width="40px" Wrap="false" />
</asp:TemplateField>
参照:<asp:GridView ID="GridView1" Width="100%" runat="server" HorizontalAlign="Center" CellPadding="2" AutoGenerateColumns="False" DataKeyNames="InfoCode" PageSize="4" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing" OnRowDataBound="GridView1_RowDataBound">
<RowStyle CssClass="DataListBK1" />
<AlternatingRowStyle CssClass="DataListBK2" />
<HeaderStyle CssClass="DataListTitle" />
<Columns>
<asp:TemplateField HeaderText="选择" >
<ItemTemplate>
<asp:CheckBox ID="chkChecked" runat="server" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Wrap="false"/>
<HeaderStyle Width="40px" Wrap="false" />
</asp:TemplateField>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询