Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / DataGrid / March 2004

Tip: Looking for answers? Try searching our database.

Find controls in Data Grid Header Template

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David McCormack - 24 Mar 2004 19:23 GMT
I have added a control in the headertemplate of a
datagrid.  it's a dropdownlist control.  What I want to
be able to do is populate that control based on some
data.  My problem is that I can't access the control.  

I tried:  
DataGrid1.FindControl("frmpriority")
and
(DropDownList)DataGrid1.FindControl("frmpriority")
and
frmpriority (as if it were just a normal control outside
of the datagrid)

but those don't work, it simply cannot find the control.
               
How can I access the field:

code snippet:
    <asp:templatecolumn>
    <headertemplate>
          Priority<br>
<asp:dropdownlist runat="server"
id="frmpriority"></asp:dropdownlist>           
        </headertemplate>
    <itemtemplate>
        Content                   
    </itemtemplate>               
    </asp:templatecolumn>

thanks
Marshal Antony - 29 Mar 2004 00:53 GMT
Hi David,

    Do it in your ItemDataBound event of the datagrid.
if (e.Item.ItemType == ListItemType.Header)

{

DropDownList ddl1=(DropDownList)e.Item.Cells[index].Controls[index];

ddl1.DataSource=your data source (Eg :data reader or dataset) ;

ddl1.DataValueField="coulmn name";

ddl1.DataTextField="column name";

ddl1.DataBind();

}

put the right index for the cell and control.

Hope this helps.

Regards,

Marshal Antony

.NET Developer

http://www.dotnetmarshal.com

> I have added a control in the headertemplate of a
> datagrid.  it's a dropdownlist control.  What I want to
[quoted text clipped - 26 lines]
>
> thanks

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.