Click here to Skip to main content
15,917,702 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a problem
In my Database,i have Colum gender type is bit and in aspx i have link
So how do check if Gender is men => display link a
else Gender is women=> hidden link a
Posted

example:

i mean like this

gender men = 1
gender women = 0

Put this in code source

SqlConnection con = new SqlConnection(strcon);
con.Open();
string strSql = "";

strSql = " select gender from Table_Gender ";
SqlCommand objCmd = new SqlCommand(strSql, con);
SqlDataReader dr = objCmd.ExecuteReader();
if (dr.Read())
{
If (dr["gender"].ToString() == 1)
link_gender.visible = true;
else
link_gender.visible = false;
}
 
Share this answer
 
Comments
Thắng Cv 17-Jun-13 23:11pm    
That good idea.Tks so much
With code. It depends on the sort of object you're using to show your data, if it's a repeater, it's easier to write code, otherwise you probably need to use an itemdatabound event to examine your data and change what is rendered accordingly.
 
Share this answer
 
Comments
Thắng Cv 17-Jun-13 22:59pm    
I use to datagrid display data.you can say the specific
Christian Graus 17-Jun-13 23:01pm    
Yes, do what I said. Handle the itemdatabound event, examine your data and then hide the control you don't want visible for females. You don't want to add controls in code if you can help it, it tends to be a mess. Another alternative is to create a template where the control is there, but not visible if it's female, by putting it in a div that has the visibility set.
Thắng Cv 17-Jun-13 23:10pm    
Ok i will try it

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