Firstly, it doesn't look like you are returning a column named "EmpID". This is an issue with your SQL statement and, IMHO, is outside of the scope of this question. That being said, once you fix the SQL, here is how you would go about binding a label in the header of the repeater.
You can use the repeater's OnItemDataBound method and look for the e.Item.ItemType
of Header
.
First, bind the repeater to the OnItemDataBound
event. You can do this on the client-side or the server side:
Client Side:
<asp:Repeater ID="rptSample" runat="server" OnItemDataBound="rptSample_ItemDataBound">
Server Side:
protected override void OnInit(EventArgs e) { base.OnInit(e); this.rptSample.ItemDataBound += rptSample_ItemDataBound; }
Then you need to check the type of item being bound in the ItemDataBound method. Like so:
protected void rptSample_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Header)
{
}
}
To be able to access the datasource (dt3
) from inside the rptSample_ItemDataBound
method, you need to make it a page-level variable. So alter the following line:
DataTable dt3 = ds3.Tables[0];
Place the following line so it is a page-level variable
DataTable dt3 = null;
and change the dt3 assignment line to this:
dt3 = ds3.Tables[0];
Then your ItemDataBound method will look like this:
protected void rptSample_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Header)
{
((Label)e.Item.FindControl("lblmonths")).Text = dt3.Rows[0]["EmpId"].ToString();
}
}