|
-
Jan 13th, 2006, 08:51 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Template columns
Hi all,
Hopefully someone can help me out with this. I have a datagrid with several columns (initially bound). I have code in place to use the datagrid headers to sort when they are clicked upon. this is working fine. I want to now add a dropdownlist to a couple of the headers. I have changed one of the required columns to a template column and added the asp control withing the <HeaderTemplate> tags. The problem is now that once i do this, the initial title disappears and i'm only left with the Dropdownlist. How can i include both the header link for sorting and also the dropdownlist.
Many Thanks.
Grant
-
Jan 13th, 2006, 08:57 AM
#2
Re: Template columns
Show your code. How had you originally set the initial title?
-
Jan 13th, 2006, 10:03 AM
#3
Thread Starter
Addicted Member
Re: Template columns
Initial asp code is as follows
Code:
<asp:BoundColumn DataField="Owner" SortExpression="Owner" HeaderText="Owner">
<HeaderStyle Width="60px"></HeaderStyle>
</asp:BoundColumn>
when i convert the column to a template column i get this:
Code:
<asp:TemplateColumn SortExpression="Owner" HeaderText="Owner">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Owner") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
and I then add the headertemplate to get this:
Code:
<asp:TemplateColumn SortExpression="Owner" HeaderText="Owner">
<HeaderTemplate>
<asp:DropDownList Runat="server" ID="ddlOwner"></asp:DropDownList>
</HeaderTemplate>
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Owner") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
The header title is initially "Owner" from which i could click on and it would fire the sortcommand event which does some code.
After the headertemplate is added The "Owner" link is no longer shown, only the drop down list.
Does this make a little more sense? Its as if the HeaderTemplate overwrites anything previously assigned to Header.
-
Jan 13th, 2006, 11:29 AM
#4
Re: Template columns
Yes it does, because I think the HeaderTemplate does overwrite any text previously added. Because it is you who is now defining what the header will contain. Very similar to the analogy of converting from a bound column to a template column.
So, right before your asp ropDownList in the HeaderTemplate, add a label with your text on it.
-
Jan 16th, 2006, 03:54 AM
#5
Thread Starter
Addicted Member
Re: Template columns
Thanks for that. I can understand the overwriting part of it but i have another problem. Its not just a label thats in the datagrid header, its a link that allows sorting on the column, I'm not sure how this would be dealt with inside the Header Template.
And finally one other problem, I want to execute some code when i change the selected index of the DropDownlist. I have included the "OnSelectedIndexChanged" tag in the HTML view and pointed it towards a sub:
DropDown_SelectedIndexChanged
This should run this code:
Code:
protected void DropDown_SelectedIndexChanged(object sender, System.EventArgs e)
{
DropDownList DDL = (DropDownList)sender;
lbl_FilterString.Text = DDL.SelectedItem.Value;
}
For some reason it doesn't execute this event when the drop downlist is changed. Any ideas why this is the case?
Many thanks for your help and patience.
-
Jan 17th, 2006, 03:49 AM
#6
Thread Starter
Addicted Member
Re: Template columns
Got it sorted myself. I added a link button in the header template to which I set the commandname and commandarguments to allow the sort to work. The dropdownlist select is now also working. It seems that i was binding the grid on the post back and this was cancelling the code run when a selected index is changed.
Thanks for the help.
Grant
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|