Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GridView header

Status
Not open for further replies.

developer155

Programmer
Jan 21, 2004
512
US
Hi,
I have a gridview that shows data. I need to use HTML to display gridview headers. The reason I am using htm is because one of the headers shoudl call JS function when clicked. The problem is that the html header does nto lign up with gridview. How can I align them and also remove the placeholders for headings in gridview. Here is my code:

<table cellpadding="0" cellspacing="0" border="0" class="lists">

<tr class="header">
<th class="id">ID</th>
<th class="name">list&nbsp;name</th>
<th class="dbTable">table&nbsp;name</th>
<th class="edit"><img src="media/i_add.gif" alt="add" onclick="rowAdd()" /></th>
<th class="delete">&nbsp;</th>
</tr>

<tr>
<td>
<asp:gridview id="CustomLists"
autogeneratecolumns="false"
allowpaging="true"
runat="server"
OnRowDataBound="CustomLists_RowDataBound">

<Columns>

<asp:BoundField ReadOnly="True" DataField="customListID" SortExpression="customListID" ItemStyle-CssClass="id"></asp:BoundField>
<asp:BoundField ReadOnly="True" DataField="name" SortExpression="name" ItemStyle-CssClass="name"></asp:BoundField>
<asp:BoundField ReadOnly="True" DataField="source" SortExpression="source" ItemStyle-CssClass="dbTable"></asp:BoundField>
<asp:TemplateField ItemStyle-CssClass="edit">
<ItemTemplate>
<img alt="Edit" runat="server" id ="Edit" src="media/i_edit.gif" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="" ItemStyle-CssClass="delete">
<ItemTemplate>
<img alt="Edit" runat="server" id ="Delete" src="media/i_delete_disabled.gif" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:gridview>


</td>
</tr>
</table>
 
However, saying hat why do you need a seperate table? A seperate table is a good way of having fixed headers so they remain static whilst your data scrolls, but it doesn't appear that is what you want. Why can't you just add your js to the column header?


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
if I do somethign like
<asp:TemplateField HeaderImageUrl="add_new.jpg" ItemStyle-CssClass="edit">
<ItemTemplate>
<img alt="Edit" runat="server" id ="Edit" src="media/i_edit.gif" />
</ItemTemplate>

how can I assign onclick attribute in code behind to this header? I only need JS to be executed when header image(add_new.jpg) is clicked , not the items. TemplateField does not have ID, like ItemTemplate

thanks
 
You can access each cell of a GridView by using e.Row.Cells(0) in the RowDataBound event of the GridView. You could then just use Attributes.Add to add your javascript.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top