根据其他列值在gridview中显示列 [英] Display a column in gridview based on other column value
问题描述
大家好,
我对C#中的gridview有疑问。
我有一个gridview控件,我从中获取值数据库表并使用 boundfield 在gridview上显示它们。我在gridview Aging 中有一列,每天都在计算。 gridview有一个链接按钮查看详细信息,一旦我们点击它,它就会重定向到下一页,它也有一个gridview,并且这里也会从数据库中获取值。第二个gridview有一个列 Status ,其值可以是'Pending'或Closed。
现在我想要的是如果第二个gridview中的所有记录都有状态 ='已关闭'然后我想在第一个网格视图中显示列 TotalAge (该列在数据库中可用),但是如果任何记录具有状态'待定'然后我想在第一个gridview中显示 Aging 列。
因此摘要是我要显示 Aging 或总老化列基于另一个gridview的列的值。
我可能没有正确解释它,所以如果您有任何问题,请随时询问。 />
期待您的帮助。
谢谢
我是什么尝试过:
互联网上没有任何相关信息
Hello all,
I have a question regarding gridview in C#.
I have a gridview control and i am fetching values from a database table and displaying them on gridview using boundfield. I have one column in gridview Ageing which is being calculated on daily basis. The gridview has a link button View Details and once we click on it, it redirects to next page which has also a gridview and the values are being fetched from database here as well. The second gridview has a column Status which can have value of 'Pending' or Closed.
Now what i want is if all the records in the second gridview has the Status = 'Closed' then i want to display a column TotalAge (The column is available in the database) in the first gridview but if any record has a status 'Pending' then i want to display the column Ageing in first gridview.
So the summary is i want to display either Ageing or Total Ageing Column based on the value of a column of another gridview.
I might not have explained it correctly so if you have any questions please feel free to ask.
Looking forward to your help.
Thanks
What I have tried:
Nothing related to this available on internet
推荐答案
你不是分享任何代码,按照我的猜测(假设)
通过分隔分隔符再发送一个命令参数。
You are not share any code, So as per my guess(assumption)
Send one more command argument by separating separator.
<itemtemplate>
<asp:LinkButton ID="lnk" runat="server" Text="change status" OnClick="lnk_Click" CommandArgument='<%# Eval("Url")+ ";" +Eval("Status")>'></asp:LinkButton>
</itemtemplate>
protected void lnk_Click()
{
string strVal = e.CommandArgument.ToString();
string[] arg = new string[2];
// split command argument
char[] splitter = { ';' };
arg = strVal .Split(splitter);
// Get url
string strUrl = arg[0].ToString();
//Get staus
string strStatus = arg[1].ToString();
// Do whatever with status
}
请分享相关代码
Please share relevant code
这篇关于根据其他列值在gridview中显示列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!