GRIDVIEW 得不到绑定列的文本值

wang520d wang520d 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我给girdview绑定了23列 其中前几列是固定的,其余的列是通过直接取数据绑定的 从数据库中取出来是什么样就绑定什么样
代码如下:
问题:除了这几个固定列能取到页眉的文本值 后面动态绑定的页眉值都为空 可是显示的时候确实显示了页眉 ,请高手赐教!

if (e.Row.RowType == DataControlRowType.Header)
{
for (int iColums = 0; iColums < dt.Rows.Count; iColums++)
{//循环在列表中要隐藏显示的列
strColums = dt.Rows[iColums][0].ToString();
for (int iCells = 0; iCells < e.Row.Cells.Count; iCells++)
{//循环当前绑定列表,从中找到与当前要隐藏的列名同名的表头列,将该cells置为false以达到隐藏显示列的目的
if (e.Row.Cells[iCells].Text == strColums)
{//这个地只有前面几个固定列能取到页眉的文本值 其余都为空 e.Row.Cells[iCells].Visible = false;
lInt.Add(iCells);
break;//找到后跳出内层循环继续循环要隐藏的下一列
}
}
}
}


<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" OnSorting="GridView1_Sorting" AllowSorting="True"
Width="100%" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound"
CssClass="border" OnRowCreated="GridView1_RowCreated">
<AlternatingRowStyle HorizontalAlign="Center" CssClass="dbtable_data1" />
<RowStyle HorizontalAlign="Center" CssClass="dbtable_data2" VerticalAlign="Middle"></RowStyle>
<HeaderStyle CssClass="dbtable_title"></HeaderStyle>
<FooterStyle HorizontalAlign="Center" VerticalAlign="Middle"></FooterStyle>
<Columns>
<asp:TemplateField HeaderText="编号">
<HeaderStyle Width="2px" />
<ItemStyle Width="2px" />
<ItemTemplate>
<asp:Label ID="lblNum" runat="server" Text='<%# Container.DataItemIndex + 1 %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="编辑">
<HeaderStyle Width="40px" />
<ItemTemplate>
<asp:LinkButton ID="LinkButtonEdit" runat="server" CommandName="edititem" CommandArgument='<%# Eval(PKField) %>'>
<asp:Image runat="server" AlternateText="编辑" ID="Image1" ImageUrl="~/img/modify.gif">
</asp:Image>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="删除">
<HeaderStyle Width="40px"></HeaderStyle>
<ItemTemplate>
<asp:LinkButton ID="LinkButtonDelete" runat="server" CommandName="deleteitem" CommandArgument='<%# Eval(PKField) %>'>
<asp:Image ID="Image2" runat="server" ImageUrl="~/img/delete.gif" AlternateText="删除">
</asp:Image>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="查看">
<HeaderStyle Width="40px"></HeaderStyle>
<ItemTemplate>
<asp:LinkButton ID="LinkButtonLook" runat="server" CommandName="lookitem" CommandArgument='<%# Eval(PKField) %>'>
<asp:Image ID="Image3" runat="server" ImageUrl="~/img/look.gif" AlternateText="查看详细">
</asp:Image>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="<input type='checkbox' name='allbox' onclick='javascript:selectAll();'"
Visible="false">
<HeaderStyle Width="2%"></HeaderStyle>
</asp:TemplateField>
</Columns>
<SelectedRowStyle BackColor="Cyan" CssClass="dbtable_data3" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
...全文
评论 28
收藏 已收藏
分享
返回顶部
wang520d
.NET社区 62,272 成员 668,968 内容