Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
Label displayNameLabel = DetailsView1.FindControl("lblDisplayName") as Label;
if (displayNameLabel == null)
{
throw;
}
string testResult = ds.Tables[0].Rows[0][0].ToString();

it is not possible to store the value from testResult to displayNameLable...
please solve this problem....
Posted
Updated 29-Nov-10 23:15pm
v3
Comments
Sunasara Imdadhusen 29-Nov-10 2:35am    
What is error?
Sunasara Imdadhusen 29-Nov-10 3:13am    
Please provide complete detail of error!
Versile 30-Nov-10 11:14am    
If displayNameLabel is null then you need to find the label. Assuming it's in template in a Detailsview, first thing you want to do is ensure it's not inside a panel or something similar. If it is you need to find the panel then find the label inside the panel... Either scenario we can't really help unless you tell us what the case is, either displayNameLabel is null or your dataset is not returning a result for that column/row selection of yours.

<pre lang="cs">
Panel detailsPanel = DetailsView1.Findcontrol("detailsPanel") as Panel;
Label displayNameLabel = detailsPanel.FindControl("lblDisplayName") as Label;
</pre>

1 solution

One of two problems, either the Label findcontrol is not pulling a result or the Table is in fact not pulling a result. Easy way to figure that out is to grab the table as a string and the label as a label.

C#
Label displayNameLabel = DetailsView1.FindControl("lblDisplayName") as Label;
if (displayNameLabel == null)
{
     throw;
}
string testResult = ds.Tables[0].Rows[0][0].ToString();


Then it's just a matter of correcting the individual error. This is a very widely requested issue though and the finding of controls can be tricky. It must be a template, and it must of course be a label, and if it's in DetailsView you can easily set up binding from the designer instead of manually in code behind... Google DetailsView binding for more help or look at this example Using TemplateFields in the DetailsView Control.
 
Share this answer
 

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