Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 28-Nov-10 21:01pm
Edited 30-Nov-10 0:15am
v3
Comments
Sunasara Imdadhusen at 29-Nov-10 2:35am
   
What is error?
Sunasara Imdadhusen at 29-Nov-10 3:13am
   
Please provide complete detail of error!
Versile at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
 
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.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 6,045
1 DamithSL 4,611
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 30 Nov 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100