网格视图评估问题 [英] Grid view Eval problem

查看:53
本文介绍了网格视图评估问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SQLDataSource控件,该控件绑定到ASP.net
GridView控件.它输出一个用户角色列表,管理员可以赋予其状态,例如用户,管理员或已禁用
在我的gridview中,有一个名为状态"的列,该列绑定到
数据库中的一列,称为"isCompanyAdmin".零表示用户,而
一个表示管理员状态.

显示0或1很难看,我想使用USER或Admin.我没办法
找出如何获取我的SQLDataSource控件的行,以便我可以查看
它们并写出文本,而不是数据库中的内容(0或1).

我的代码是这样的:

I have an SQLDataSource control, which is bound to an ASP.net
GridView control. It outputs a list of user roles that a admin can give status like user,admin or disabled
In my gridview, I have a column called "Status" which is bound to
a column in my database, called "isCompanyAdmin". A zero means User, and a
one means Admin status.

Showing a 0 or 1 is ugly and I want to use USER or Admin. I can''t figure
out how to get at my SQLDataSource control''s rows so that I can look at
them and write text out, rather than what''s in the database (a 0 or 1).

My code is like this:

<asp:Label ID="lbStatus" runat="server" text='<%# Eval("isCompanyAdmin")
%>' />

I've tried assiging the return value of Eval("isCompanyAdmin") to a local
variable, but I get asp errors telling me that Eval must be used in a
databound control.

I want to do something like this:

If Eval("CheckedOut") = "0" Then
...
Else
...
End Of



我可以发布真实的代码(如果有帮助的话),但这更多的是我的方法
寻找...

感谢您的帮助



I can post real code if that helps- but it''s more the approach I am
looking for...

Thanks for any help

推荐答案

在某处使用静态方法将布尔值转换为字符串.
然后尝试这样的事情

Make a static method somewhere to convert the boolean into a string.
Then try something like this

<asp:label id="Label2" runat="Server" text="<%#YourNamespace.SomeClass.MethodName((System.Boolean)Eval("isCompanyAdmin")) %>"/>


我已经部分完成了此解决方案以使用此
公共字符串checkstatus(int状态)
{
如果(状态== 1)
{
返回管理员";
}
否则,如果(状态== 0)
{返回用户"; }
其他{
返回已禁用";

}


aspx页面//

< ItemTemplate>
< asp:标签ID ="lbstatus"文本=''<%#checkstatus(Convert.ToInt32(Eval("IsCompanyAdmin")))%>''runat ="server"/>
</ItemTemplate>


但是现在我出现了问题
在我的数据库中,有两个不同的列IsComapnyAdmin和IsDeleted
如果IsCompanyAdmin IsDeleted ==状态
0 0,然后用户

1 0然后admin
0 1然后禁用

如何使用两个Eval,以及如何比较和解决这个复杂的问题
我想在gridview加载时打印user,admin,disabled值及其值,如上述两列...
请帮助我
i have done this solution partially to use this
public string checkstatus(int status)
{
if (status == 1)
{
return "Admin";
}
else if (status == 0)
{ return "User"; }
else {
return "Disabled";

}


aspx page//

<ItemTemplate>
<asp:Label ID="lbstatus" Text=''<%#checkstatus(Convert.ToInt32(Eval("IsCompanyAdmin"))) %>'' runat="server" />
</ItemTemplate>


But now i have problem arise
in my database there are two different column IsComapnyAdmin and IsDeleted
if IsCompanyAdmin IsDeleted ==status
0 0 then User

1 0 then admin
0 1 then disabled

how i can use two Eval and how can i compare and solve this complex problem
i want to print user,admin,disabled value when gridview load and its value like above two column...
Please Help me


尝试使用Grid View OnRowDataBound事件为该事件编写事件处理程序,并在该事件处理程序中编写条件,然后将结果分配给标签,如下所示

在事件处理程序中,编码如下所示

受保护的void grdVw_OnRowDataBound(object sender,GridViewRowEventArgs e)
{
如果(e.Row.RowType == DataControlRowType.DataRow)
{
标签lblStatus =(Label)e.Row.FindControl("lblStatus");
int isDet = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem,"IsDeleted")));
int isAdm = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem,"IsCompanyAdmin"));
//现在将这两个变量作为您的条件进行比较,并将最终值分配给label,如下所示

lblStatus.Text =您的结果";

}
}
Try to Use Grid View OnRowDataBound event Write a event handler to this event and write you condition in that event handler and assign the resultant to the label as below

in the event handler the coding is as like below

protected void grdVw_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblStatus = (Label)e.Row.FindControl("lblStatus");
int isDet = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem,"IsDeleted"));
int isAdm = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "IsCompanyAdmin"));
//Now Compare these two variables as your criteria and assign the final value to label as below

lblStatus.Text = "Your Result";

}
}


这篇关于网格视图评估问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆