Click here to Skip to main content
14,869,731 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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..
Posted
Comments
Amod Kumar Jaiswal 16-Nov-11 3:25am
   
you just fire grid row data bound and check condition if true then write on control text Active else Expire
sriranganadhk 16-Nov-11 4:21am
   
if u dont mine will u send me sample code for this...plz
Amod Kumar Jaiswal 16-Nov-11 23:00pm
   
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 ";
}
}
}

}

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
   
you can use this link that may help.

Dynamically adding column and controls into a gridview[^]
   
Comments
S.P.Tiwari 16-Nov-11 5:18am
   
to fill the dataset you can use your mechanism
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 ";
}
}
}

}
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900