how to bind data in gridview header template ?

Posted by Gow.Net under ASP.NET on 10/28/2012 | Points: 10 | Views : 42559 | Status : [Member] | Replies : 3
hi in my application i am using grid-view

  <asp:GridView ID="gridview_shareimage" runat="server" AutoGenerateColumns="false" 
Width="267px">
<Columns>
<asp:TemplateField HeaderText="Post Image">
<HeaderTemplate>
</HeaderTemplate>

<ItemTemplate>
<table>
<tr>
<td>
<asp:Image ID="Image1" runat="server" Height="100px" Width="100px" ImageUrl='<%# "Imagehandler.ashx?Imgid1="+ Eval("Photo_id") %>' ToolTip='<%# Eval("Description") %>' />
</td>
<td>
<asp:Label ID="lbl_description" runat="server" Text='<%# Eval("Description") %>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

here how to bind data in HeaderTemplate ?

gowthaman8870226416


Responses

Posted by: Ranjeet_8 on: 10/29/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Try this,

<asp:GridView ID="gridview_shareimage" runat="server" AutoGenerateColumns="false"
Width="267px">
<Columns>
<asp:TemplateField HeaderText="Post Image">
<HeaderTemplate>
<table>
<tr>
<td style="width: 117px;" align="center">
Image
</td>
<td style="width: 160px;" align="center">
Description
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Image ID="Image1" runat="server" Height="100px" Width="100px" ImageUrl='<%# "Imagehandler.ashx?Imgid1="+ Eval("Photo_id") %>'
ToolTip='<%# Eval("Description") %>' />
</td>
<td>
<asp:Label ID="lbl_description" runat="server" Text='<%# Eval("Description") %>'></asp:Label>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>


Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 10/29/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

try this code
client Side

<asp:TemplateField HeaderText ="Headter CourseName">

<HeaderTemplate>
<asp:TextBox ID="TextBox3" runat ="server" Text =""></asp:TextBox>
</HeaderTemplate>

</asp:TemplateField>

<asp:TemplateField>


server Side

protected void Gv1_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.Header)
{
((TextBox)e.Row.FindControl("TextBox3")).Text = "Some data";
}


Mark as Answer if its helpful to you

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sourabh07 on: 10/30/2012 [Member] Starter | Points: 25

Up
0
Down
hi to all,

we are having AutoGenerateColumns property in GridView, if we set it to true then the heder template will bind according to the datasource and if we set it to false then we have to manually bind it.

If it is false, then either we can bind at design time or at run time.

At design time:

<HeaderTemplate>

<asp:Label ID="lbl" runat ="server" Text ="Employee Name"></asp:Label>
</HeaderTemplate>


At run time

(e.HeaderRow.FindControl("lbl") as Label).Text="Employee Name"




Sourabh07

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response