动态地在GridView中设置值 [英] Dynamically how to set value in gridview
本文介绍了动态地在GridView中设置值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友们,
我的gridview有问题.
sno,username,active/Expired中有三个字段.
在这里,必须在活动/过期字段中显示用户有效日期,这意味着actve和userdate已过期意味着活动/过期字段中的内容已过期.
如何比较sql 2005 db中的该字段并使该字段处于活动状态或过期??
对不起,我的英语不好..
Hi friends,
I have a problem with gridview.
there are three fields in sno , username , active/Expired.
here in active/Expired field i have to show user is valid to date means actve and userdate is expired means Expired in active/Expired field.
how to compare this field from sql 2005 db and get this field active or expired??
sorry for my poor english..
推荐答案
基本上,您需要创建一个数据集实例,一个查询之外的数据适配器实例,使用它来填充数据集或其数据表,并使用数据集将您的网格视图实例与之绑定;请参阅此MSDN帮助页面和代码示例: http://msdn.microsoft.com/en-us/library/fkx0cy6d.aspx [ ^ ].
—SA
Basically, you need to create an instance of data set, an instance of data adapter out of your query, use it to fill a data set or its data table and use data set to bind your instance of grid view with; see this MSDN help page and a code sample: http://msdn.microsoft.com/en-us/library/fkx0cy6d.aspx[^].
—SA
您可以使用此链接可能会有所帮助.
动态地将列和控件添加到gridview [ ^ ]
you can use this link that may help.
Dynamically adding column and controls into a gridview[^]
受保护的空dvOrganization_RowDataBound(对象发送者,GridViewRowEventArgs e)
{
如果(e.Row.RowType == DataControlRowType.DataRow)
{
数据表dt = objBALManageOrg.SelectOrganizationDetail();
RadioButton rdkeytype =(RadioButton)e.Row.FindControl("rdkeytype");
标签lblStatus =(Label)e.Row.FindControl("lblStatus");
if(dsOrganization.Tables [0] .Rows.Count> 0)
{
如果(Convert.ToString(dsOrganization.Tables [0] .Rows [0] ["Active"])!=")
{
如果(lblStatus.Text =="True")
{
lblStatus.Text =有效";
}
其他
{
lblStatus.Text =无效";
}
}
其他
{
lblStatus.Text =已过期";
}
}
}
}
protected void dvOrganization_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
data table dt= objBALManageOrg.SelectOrganizationDetail();
RadioButton rdkeytype = (RadioButton)e.Row.FindControl("rdkeytype");
Label lblStatus = (Label)e.Row.FindControl("lblStatus");
if (dsOrganization.Tables[0].Rows.Count > 0)
{
if (Convert.ToString(dsOrganization.Tables[0].Rows[0]["Active"]) != "")
{
if (lblStatus.Text == "True")
{
lblStatus.Text = "Active";
}
else
{
lblStatus.Text = "InActive";
}
}
else
{
lblStatus.Text = "Expired ";
}
}
}
}
这篇关于动态地在GridView中设置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文