-
ListView problem
Hello Everybody,
I have a ListView control and under ItemTemplate I have following code:
Code:
<asp:Label ID="Label1" runat="server" Text='<% #MatchCategory(dtCategories.Rows[i]["ID"].ToString().Trim(), Eval("CategoryID").ToString()) %>'></asp:Label>
The MatchCategory method just checks if two values are equal and return true or false. Just below this code I am separately printing dtCategories.Rows[i]["ID"].ToString().Trim() and Eval("CategoryID") and can see matching values but MatchCategory method always returns false.
Code:
<asp:LinkButton ID="lnkBtnClass" runat="server" OnClick="ShowClassPopup"><%# Eval("Name") %></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" OnClick="ShowClassPopup"><% Response.Write(dtCategories.Rows[i]["ID"].ToString().Trim()); %></asp:LinkButton>
Here's my MatchCategory method.
Code:
public bool MatchCategory(string CategoryID1, string CategoryID2)
{
if (CategoryID1.Trim() == CategoryID2.Trim())
return true;
else
return false;
}
Any idea as to why I am always getting false?
Thanks.
-
Re: ListView problem
Hey,
Have you set a breakpoint on this line:
Code:
if (CategoryID1.Trim() == CategoryID2.Trim())
Put both values into the watch window?
What do they come back as?
Gary
-
Re: ListView problem
This could be very easier if I could put a breakpoint. Actually it is a Microsoft CRM online web application and it doesn't run on my local PC because of web service references etc, so I need to put the code on the server to see whats happening.
Thanks.
-
Re: ListView problem
Hey,
Where is the Server? Is it under your control? It is not possible that you can do Remote Debugging?
Failing that, I would suggest adding some logging to your application, so that you can trace through what is happening.
Gary
-
Re: ListView problem
Hello gep13,
The server is not under my control but I put the code to write variable values in text file in MatchCategory method. I found that 'i' is always zero, hence its always trying to match first row of dtCategories. Interestingly, just below the MatchCategory method, I am printing dtCategories[i]["ID"] and its giving all four values (dtCategories has 4 rows) but while sending to MatchCategory, 'i' is zero.
Code:
<asp:Label ID="Label1" runat="server" Text='<% #MatchCategory(i.ToString(),dtCategories.Rows[i]["ID"].ToString().Trim(), Eval("CategoryID").ToString()) %>'></asp:Label>
<asp:LinkButton ID="LinkButton2" runat="server" OnClick="ShowClassPopup"><% Response.Write(dtCategories.Rows[i]["ID"].ToString().Trim()); %></asp:LinkButton>
Thanks.
-
Re: ListView problem
Hey,
Response.Write's, although they seem like a good idea, they are really not. They are lnown to give spurious results, and can't be trusted. Much better to write directly to a Text property of a control, or add something like log4net to your application.
I would strongly encourage you not to do this (marked in bold):
Code:
<asp:Label ID="Label1" runat="server" Text='<% #MatchCategory(i.ToString(),dtCategories.Rows[i]["ID"].ToString().Trim(), Eval("CategoryID").ToString()) %>'></asp:Label>
Do this work in your server side code, you will have much more control over what is going on.
Gary