my table has a field named Gender with datatype bit. I'm storing true or false values. While reading with a formview, formview itemtemplate displays a checkbox. What i want to do is to show "Male" or "Female" in a textbox.
I'm sorry this is working but i have one more issu related to this.
<asp:RadioButtonList id="ButtonList" Runat="Server">
<asp:ListItem Value="1" Text="Red"/>
<asp:ListItem Value="2" Text="Green"/>
<asp:ListItem Value="3" Text="Blue"/>
</asp:RadioButtonList>
i have something like above. How can i bind saved values (1,2,3,...) from database to a textbox or label.
esmerman
Member
24 Points
73 Posts
Custom value for bit type fields
Apr 30, 2012 06:54 PM|LINK
Hi, i am new to asp.net.
my table has a field named Gender with datatype bit. I'm storing true or false values. While reading with a formview, formview itemtemplate displays a checkbox. What i want to do is to show "Male" or "Female" in a textbox.
How can i achieve this with formview.
Any helps will be appreciated.
adeelehsan
All-Star
18593 Points
2789 Posts
Re: Custom value for bit type fields
May 01, 2012 05:22 AM|LINK
You should have stored it in a different data type. Anyways, tt will be easy if you write a custom query for that. Like:
See the following link for more info:
http://msdn.microsoft.com/en-us/library/ms181765.aspx
MCPD ASP.NET 4.0 and 3.5, MCTS WSS, MOSS, SharePoint 2010, MCT
Microsoft Community Contributor Award 2011
nijhawan.sau...
All-Star
16460 Points
3178 Posts
Re: Custom value for bit type fields
May 01, 2012 05:27 AM|LINK
You can Use CASE(T-SQL) in this scenario
esmerman
Member
24 Points
73 Posts
Re: Custom value for bit type fields
May 01, 2012 07:41 AM|LINK
Sorry for late response,
i'm using entity-framework and formview.
Where to put this code:;
"Select case gender When True Then "Male" when False Then "Female" as Gender End From Person"
Thank you
esmerman
Member
24 Points
73 Posts
Re: Custom value for bit type fields
May 01, 2012 07:44 AM|LINK
this is my entitydatasource
<asp:EntityDataSource ID="DocumentationEntityDataSource" runat="server" ContextTypeName="Documents.DAL.DocumentationEntities" EnableFlattening="False" EnableInsert="True" EntitySetName="People" ConnectionString="name=DocumentationEntities" DefaultContainerName="DocumentationEntities" Include="Department, Title, Position, Occupation, Province, County"> </asp:EntityDataSource>Qin Dian Tan...
All-Star
113532 Points
12480 Posts
Microsoft
Re: Custom value for bit type fields
May 02, 2012 08:48 AM|LINK
Hi,
You can bind the Text property of TextBox like this:
Text='<%# Convert.ToBoolean(Eval("Gender")) ? "Male" : "Female" %>'
Thanks,
If you have any feedback about my replies, please contactmsdnmg@microsoft.com.
Microsoft One Code Framework
esmerman
Member
24 Points
73 Posts
Re: Custom value for bit type fields
May 02, 2012 08:01 PM|LINK
Thank you very much .
I solved in a long way. But this is very short way.
Thanks again.
esmerman
Member
24 Points
73 Posts
Re: Custom value for bit type fields
May 02, 2012 08:27 PM|LINK
I'm sorry this is working but i have one more issu related to this.
Qin Dian Tan...
All-Star
113532 Points
12480 Posts
Microsoft
Re: Custom value for bit type fields
May 03, 2012 02:33 AM|LINK
Hi,
Have to handle the event in code behind to loop the datasource and generate a string separated by ','.
Thanks,
If you have any feedback about my replies, please contactmsdnmg@microsoft.com.
Microsoft One Code Framework
esmerman
Member
24 Points
73 Posts
Re: Custom value for bit type fields
May 03, 2012 06:09 AM|LINK
Thank you very much