asp.net – GridView的RowDataBound函数
发布时间:2020-05-23 21:24:20 所属栏目:asp.Net 来源:互联网
导读:我有一个包含3个字段的DataTable:ACount,BCount和DCount.如果ACount 0然后我需要在GridView的一列中显示S.如果ACount 0然后我必须在该列中显示“D”(在标签中).与BCount和DCount相同.如何在RowDataBound函数中执行此条件检查? GridView OnRowDataBound活动
|
我有一个包含3个字段的DataTable:ACount,BCount和DCount.如果ACount< 0然后我需要在GridView的一列中显示'S'.如果ACount> 0然后我必须在该列中显示“D”(在标签中).与BCount和DCount相同.如何在RowDataBound函数中执行此条件检查? 解决方法GridViewOnRowDataBound活动是您的朋友:
<asp:gridview
id="myGrid"
onrowdatabound="MyGrid_RowDataBound"
runat="server">
<columns>
<asp:boundfield headertext="ACount" datafield="ACount" />
<asp:boundfield headertext="BCount" datafield="BCount" />
<asp:boundfield headertext="DCount" datafield="DCount" />
<asp:templatefield headertext="Status">
<itemtemplate>
<asp:label id="aCount" runat="server" />
<asp:label id="bCount" runat="server" />
<asp:label id="dCount" runat="server" />
</itemtemplate>
</asp:templatefield>
</columns>
</asp:gridview>
// Put this in your code behind or <script runat="server"> block
protected void MyGrid_RowDataBound(object sender,GridViewRowEventArgs e)
{
if(e.Row.RowType != DataControlRowType.DataRow)
{
return;
}
Label a = (Label)e.Row.FindControl("aCount");
Label b = (Label)e.Row.FindControl("bCount");
Label d = (Label)e.Row.FindControl("dCount");
int ac = (int) ((DataRowView) e.Row.DataItem)["ACount"];
int bc = (int) ((DataRowView) e.Row.DataItem)["BCount"];
int dc = (int) ((DataRowView) e.Row.DataItem)["DCount"];
a.Text = ac < 0 ? "S" : "D";
b.Text = bc < 0 ? "S" : "D";
d.Text = dc < 0 ? "S" : "D";
}
我不确定你想要’S’和’D字符呈现的位置,但你应该能够重新设置以满足你的需求. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 是否可以为post和get提供重复的动作名称和参
- asp.net-mvc – 如何在ASP.NET MVC中执行[RequireHttps(Red
- asp.net-mvc – 如何将数据从AuthorizeAttribute传递给Cont
- asp.net-mvc – ASP.NET MVC路由和静态数据(即图像,脚本等)
- asp.net-mvc – 如何持久保存用户选择(例如:主题选择)
- asp.net-mvc – 如何根据设备类型更改ASP.NET MVC视图?
- asp.net-mvc – HandleError属性没有任何效果
- 如何从ASP .NET网站检测客户端上安装的Java运行时?
- asp.net-mvc – 捕获文件名作为参数的MVC路由
- ASP.NET中没有会话状态的用户身份验证
推荐文章
站长推荐
- asp.net-mvc-2 – TempData未按预期清除
- 在ASP.Net Cookie或会话状态中存储会话信息?
- asp.net-mvc – ASP.NET MVC中的全局错误处理(控
- asp.net – 为不同项目中的所有Web应用程序网页添
- asp.net-mvc – 如何在ASP.NET控制器中获
- asp.net – ‘WebForm_DoPostBackWithOptions’在
- asp.net – 从global.asax – mvc重定向到一个动
- asp.net-mvc – 在braintree的localhost上测试We
- ASP.NET MVC 4 / Web API – 为Accepts插入Razor
- 如何将纯文本发布到ASP.NET Web API端点?
热点阅读
