i have a label in itemtemplate of gridview.want to access value of dat label bt its giving me null value.my code is:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
public void bind()
{
string qry = "SELECT tbl_artists.name as ArtistName, tbl_artists.profilePic as Pic,tbl_venues.name AS VenueNmae,convert(varchar(50),tbl_ArtistSchedule.Date,105)as Date, tbl_ArtistSchedule.Time FROM tbl_ArtistSchedule INNER JOIN tbl_artists ON tbl_ArtistSchedule.artistId = tbl_artists.artistId INNER JOIN tbl_venues ON tbl_ArtistSchedule.venueId = tbl_venues.venueId";
ds = obj.fillds(qry);
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
Label lbl1 = (Label)e.Row.FindControl("lblday");
string date = lbl1.Text;
}
Loading
Suthish NairPosted Mar 12, 2011, 12:49 PM
Suthish NairPosted Mar 10, 2011, 2:25 PM
Raja KrishnamurthyPosted Mar 10, 2011, 7:34 AM
There are three things to check:
1. Check if you have given ItemTemplate for the label.
2. You got to make sure it is a Datarow in Row_DataBound before finding the control.
3. Check the exact Id of the Label control (could be lblDay)
Check out this link:
http://msdn.microsoft.com/en-us/library/aa479353.aspx
HTH
Happy Programming!!!
Regards,
Raja
Soft CornerPosted Mar 10, 2011, 7:29 AM
Write one method for finding value of labels :-
private void GetLabel()
{
foreach (GridViewRow row in GridView1.Rows)
{
string LabelText = ((Label)row.FindControl("LabelID")).Text;
Response.Write(LabelText);
}
}
and call this method from Page_Load ...