开发者

show data in gridview using condition

开发者 https://www.devze.com 2022-12-31 00:47 出处:网络
I want开发者_StackOverflow社区 to check a condition in a grid view e.g. if(loginid.equels(\'admin\'))

I want开发者_StackOverflow社区 to check a condition in a grid view e.g.

if(loginid.equels('admin'))
    query = select * from memberlist;
else
    query = select * from memberlist where memberid like 'operator%';

depending on the query the grid view will display the list of members and also where to put this code in .cs or .aspx and how?


Write this code in the place where u need to check d condition and it would work.

 string query = string.empty;
if(loginid.equels('admin')) 
{
    query = "select * from memberlist";         
}
else
{
    query = "select * from memberlist where memberid like 'operator%'";
}
SqlDataAdapter da = new SqlDataAdapter(query,sqlCon);
DataSet ds = new DataSet("aa");
da.Fill(ds, "ww");
gvData.DataSource = ds.Tables["ww"];
gvData.DataBind();


The place to put this kind of logic is in the cs code behind file. You can put it in the page load, and then set the DataSource of the grid to the memberlist and then call DataBind. Hope this is what your asking for?

0

精彩评论

暂无评论...
验证码 换一张
取 消