如何获得DateGrid中项模板中模板列里lable控件的值(附图高手进,在线)

ntwqy_2008 2008-12-24 01:15:54

HTML源内代码如下:
<Columns>
<asp:BoundField DataField="StudentRname" HeaderText="学员姓名" />
<asp:BoundField DataField="DepartmentName" HeaderText="部门名称" />
<asp:BoundField DataField="CourseName" HeaderText="课程名称" />
<asp:TemplateField HeaderText="第1次成绩">
<ItemTemplate>
客观成绩:<asp:Label ID="labObjScoreNum1" runat="server" Text='<%# Eval("ObjScoreNum1") %>'></asp:Label><br />
主观成绩:<asp:Label ID="labSubScoreNum1" runat="server" Text='<%# Eval("SubScoreNum1") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="第2次成绩">
<ItemTemplate>
客观成绩:<asp:Label ID="labObjScoreNum2" runat="server" Text='<%# Eval("ObjScoreNum2") %>'></asp:Label><br />
主观成绩:<asp:Label ID="labSubScoreNum2" runat="server" Text='<%# Eval("SubScoreNum2") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="第3次成绩">
<ItemTemplate>
客观成绩:<asp:Label ID="labObjScoreNum3" runat="server" Text='<%# Eval("ObjScoreNum3") %>'></asp:Label><br />
主观成绩:<asp:Label ID="labSubScoreNum3" runat="server" Text='<%# Eval("SubScoreNum3") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Pass" HeaderText="是否通过" />
</Columns>
现在要找到每个Lab的值如果是空则显示"未考",如果为-1则显示成"未评",请问在GridView1_RowDataBound中如何写呢??忘高手不吝赐教..
...全文
132 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiang_jiajia10 2008-12-24
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 Lcindep110 的回复:]
C# code
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lb= (Label)e.Row.FindControl("labObjScoreNum1");
if (lb.Text.Trim() == "")
{
lb.Text = "未考";
}
else if(lb.Text == "-1")
{

[/Quote]
这样写就会?

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{

if (e.Row.Cells[3].Text == "-1")
{

e.Row.Cells[3].Text = "未评";
}
else
{

e.Row.Cells[3].Text = "<font color=red>未考</font>";
}
}

}


给你写个例子并且告诉你
Label labObjScoreNum1 = (Label)e.Row.FindControl("lable1");
就不会变通一下么
zhxhdean 2008-12-24
  • 打赏
  • 举报
回复
楼上都给出答案了
ntwqy_2008 2008-12-24
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 Lcindep110 的回复:]
C# code
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lb= (Label)e.Row.FindControl("labObjScoreNum1");
if (lb.Text == "-1")
{
lb.Text = "未评";
}
else
{
lb.Text = "<font co…
[/Quote]
谢谢!
Lcindep110 2008-12-24
  • 打赏
  • 举报
回复

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lb= (Label)e.Row.FindControl("labObjScoreNum1");
if (lb.Text.Trim() == "")
{
lb.Text = "未考";
}
else if(lb.Text == "-1")
{
lb.Text = "未评";
}
}

}

Lcindep110 2008-12-24
  • 打赏
  • 举报
回复

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lb= (Label)e.Row.FindControl("labObjScoreNum1");
if (lb.Text == "-1")
{
lb.Text = "未评";
}
else
{
lb.Text = "<font color=red>未考</font>";
}
}

}


ntwqy_2008 2008-12-24
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 zhangguanchun 的回复:]
<asp:TemplateField HeaderText="第1次成绩">
<ItemTemplate>
客观成绩: <asp:Label ID="labObjScoreNum1" runat="server" Text=' <%# Eval("ObjScoreNum1").ToString()==""?"未考":"未评" %>'> </asp:Label> <br />
主观成绩: <asp:Label ID="labSubScoreNum1" runat="server" Text=' <%# Eval("SubScoreNum1").ToString()==""?"未考":"未评"…
[/Quote]
空显示未考,否则是未评。教师在后台评分后会插入这个字段,评分后既不为空也不是-1,..
zhangguanchun 2008-12-24
  • 打赏
  • 举报
回复
<asp:TemplateField HeaderText="第1次成绩">
<ItemTemplate>
客观成绩: <asp:Label ID="labObjScoreNum1" runat="server" Text=' <%# Eval("ObjScoreNum1").ToString()==""?"未考":"未评" %>'> </asp:Label> <br />
主观成绩: <asp:Label ID="labSubScoreNum1" runat="server" Text=' <%# Eval("SubScoreNum1").ToString()==""?"未考":"未评" %>'> </asp:Label>
</ItemTemplate>
</asp:TemplateField>
homesos 2008-12-24
  • 打赏
  • 举报
回复
应该在数据库中处理
ntwqy_2008 2008-12-24
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 sprc_lcl 的回复:]
C# code
this.GridView1.DataBind();
////////////databind后写下下面的东西.GridView1换成你的
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
GridViewRow gvr = this.GridView1.Rows[i];
if (gvr.RowType == DataControlRowType.DataRow)
{
Label labObjScoreNum1 = (Label)e.Row.FindControl("labObjScoreNum1");

[/Quote]
写在了RowDataBound中,
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
GridViewRow gvr = this.GridView1.Rows[i];
if (gvr.RowType == DataControlRowType.DataRow)
{
Label labSubScoreNum1 = (Label)e.Row.FindControl("labSubScoreNum1");
if (labSubScoreNum1.Text.Trim() == "") //未将对象引用设置到对象的实例
{
labSubScoreNum1.Text = "未考";
}
else if (labSubScoreNum1.Text.Trim() == "-1")
{
labSubScoreNum1.Text = "未评";
}
//......
}
}
rascalwm 2008-12-24
  • 打赏
  • 举报
回复
this.GridView1.Rows[index].FindControl("id") as lable
jiang_jiajia10 2008-12-24
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 ntwqy_2008 的回复:]
引用 3 楼 jiang_jiajia10 的回复:
给你写个吧

C# code
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{

if (e.Row.Cells[3].Text == "-1")
{

e.Row.Cells[3].Text = "未评";
}
else
{


[/Quote]
我只是给你写个例子。e.Row.Cells[3].Text 这需要你自己去换啊找lable用
Label labObjScoreNum1 = (Label)e.Row.FindControl("lable1");
takako_mu 2008-12-24
  • 打赏
  • 举报
回复
用FindControl來抓label的值
注意點:判斷空是if(str== )
ntwqy_2008 2008-12-24
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 jiang_jiajia10 的回复:]
给你写个吧

C# code
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{

if (e.Row.Cells[3].Text == "-1")
{

e.Row.Cells[3].Text = "未评";
}
else
{

e.Row.Cells[3].Text = "<font…
[/Quote]

这样写没用的。我本来也是这样写的可是不管用~~~~~
sprc_lcl 2008-12-24
  • 打赏
  • 举报
回复

this.GridView1.DataBind();
////////////databind后写下下面的东西.GridView1换成你的
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
GridViewRow gvr = this.GridView1.Rows[i];
if (gvr.RowType == DataControlRowType.DataRow)
{
Label labObjScoreNum1 = (Label)e.Row.FindControl("labObjScoreNum1");
if (labObjScoreNum1.Text.Trim() == "")
{
labObjScoreNum1.Text = "未考";
}
else if (labObjScoreNum1.Text.Trim() == "-1")
{
labObjScoreNum1.Text = "未评";
}
//......
}
}
jiang_jiajia10 2008-12-24
  • 打赏
  • 举报
回复
给你写个吧

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{

if (e.Row.Cells[3].Text == "-1")
{

e.Row.Cells[3].Text = "未评";
}
else
{

e.Row.Cells[3].Text = "<font color=red>未考</font>";
}
}

}

参考这个改
mengxj85 2008-12-24
  • 打赏
  • 举报
回复
foreach (GridViewRow gr in this.gvUpdatePlan.Rows)
{
HiddenField hdfPlanId = (HiddenField)gr.FindControl("hdfPlanId");
}
其他事件中
mengxj85 2008-12-24
  • 打赏
  • 举报
回复
Label labObjScoreNum1 = e.Row.FindControl("labObjScoreNum1") as Label ;
labObjScoreNum1.text

62,050

社区成员

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

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

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

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