gridview 取值问题( GV.Rows[index].Cells[2].Text.ToString()取到的是空值)

shoumangli 2008-05-29 11:55:42
GV.Rows[index].Cells[2].Text.ToString();我用这个语句取到是空值,怎么回事哦?


部分前台代码如下:
<asp:GridView ID="GV" runat="server" AutoGenerateColumns="False" AllowPaging="True"  OnRowCommand="GV_RowCommand"
OnPageIndexChanging="GV_PageIndexChanging" PageSize="15" CellPadding="4" ForeColor="Black" AllowSorting="True" Height="232px" Width="725px" BackColor="#E0E0E0" BorderColor="#E0E0E0" BorderStyle="Inset">
<Columns>
<asp:TemplateField HeaderText="编号">
<ItemTemplate>
<b>
<%# DataBinder.Eval(Container.DataItem, "ACTIVITYID") %>
</b>
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="活动主题">
<ItemTemplate>
<b>
<a href='ActivityDetail.aspx?activity_id=<%# DataBinder.Eval(Container.DataItem, "ACTIVITYID") %>'><%# DataBinder.Eval(Container.DataItem, "TITLE") %></a>
</b>
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="发布者">
<ItemTemplate>
<b>
<%# DataBinder.Eval(Container.DataItem, "ORGANIZER")%>
</b>
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="发布时间">
<ItemTemplate>
<b>
<%# DataBinder.Eval(Container.DataItem, "TIME")%>
</b>
</ItemTemplate>
</asp:TemplateField>

<asp:ButtonField Text="删除" HeaderText="删除" CommandName="Delete" />

</Columns>
...全文
533 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
amandag 2008-05-29
  • 打赏
  • 举报
回复
既然已经使用了模版列,不如使用标签存放绑定的数据

<asp:TemplateField HeaderText="发布者">
<ItemTemplate>
<b>
<%# DataBinder.Eval(Container.DataItem, "ORGANIZER")%>
</b>
</ItemTemplate>
</asp:TemplateField>
</ItemTemplate>
</asp:TemplateField>

==
<asp:TemplateField HeaderText="发布者">
<ItemTemplate>
<b>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ORGANIZER")%>'></asp:Label>
</b>
</ItemTemplate>
</asp:TemplateField>




protected void GV_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument); //待处理的行下标
string name = ((Label)(GV.Rows[index].FindControl("Label1"))).Text;
}
amandag 2008-05-29
  • 打赏
  • 举报
回复
你的Cell[2]不是BoundField,用Cells[2].Text取值有些问题
shoumangli 2008-05-29
  • 打赏
  • 举报
回复
protected void GV_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument); //待处理的行下标
string name = GV.Rows[index].Cells[2].Text.ToString();
}


绑定数据后取的;
Jinglecat 2008-05-29
  • 打赏
  • 举报
回复
在哪个事件取的?

绑定之后吗?
fancycgx3650 2008-05-29
  • 打赏
  • 举报
回复
GV.Rows[e.index].Cells[2].Text.ToString();
Ncistgg 2008-05-29
  • 打赏
  • 举报
回复
GV.Rows[index].Cells[2].Text.ToString()?
好像GV.Rows[index].Cells[2].后面有Control
shoumangli 2008-05-29
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 amandag 的回复:]
你的Cell[2]不是BoundField,用Cells[2].Text取值有些问题
[/Quote]

为什么使用了模板列就不能用Cell[2]了呢,菜鸟问题,希望能回答哦,嘿嘿
S170393163 2008-05-29
  • 打赏
  • 举报
回复 1
你用的TemplateField,建议用Label显示
<asp:TemplateField HeaderText="发布者">
<ItemTemplate>
<b>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("ORGANIZER")%>'></asp:Label>
</b>
</ItemTemplate>
</asp:TemplateField>

取值:
String str = ((Label)GV.Rows[index].FindControl("Label1")).Text;
路人乙e 2008-05-29
  • 打赏
  • 举报
回复
cell里面肯定嵌套一个control
((Label)(GV.Rows[index].Cells[2].Controls[0])).Text;
Griot 2008-05-29
  • 打赏
  • 举报
回复
你用linkbutton吧,
((LinkButton)GV.Rows[index].Cells[2].Controls(1)).Text即可

62,040

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧