开发者

show data in gridview using condition

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜