Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if statement in binding data ?

Status
Not open for further replies.

stonehead

Technical User
May 2, 2007
58
US
Hi,
Below is what I currently have.
What I want now is to add more condition to my data binding. Instead of always getting data from "message" field: Text='<%# Eval("Message") %> I want it to get data from other fields depends on the value of "status" field. Any help is greatly appreciated.

<asp:TemplateField HeaderText="Message">
<ItemStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="lblMessage" runat="server" CssClass="bodytxt" Text='<%# Eval("Message") %>' Visible='<%#IIF(CONVERT.ToString(Eval("Status"))="NEW","False","True") %>' ></asp:Label>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("ReferenceID", " %>'
Text='<%# Bind("Message") %>' Target="_blank" Visible='<%#IIF(CONVERT.ToString(Eval("Status"))="NEW","True","False") %>'> </asp:HyperLink>

</ItemTemplate>
</asp:TemplateField>
 
It would be more readable and maintainable if you put all of this logic in the code-behind page. Use the RowDataBound event of your grid.
 
Thank you for you prompt response. Could you please give me some sample codes. Let's say my gridview has 2 colums: MesgType & Message. Depends on the "Mesgtype" (reply/response), "Message" would be bound to ReplyMesg or ResMesg from my dataset table. I'm trying to learn asp.net so please excuse my limited knowledge.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top