how to find lable value in gridview [Resolved]

Posted by Gow.net under ASP.NET on 2/13/2012 | Points: 10 | Views : 11675 | Status : [Member] | Replies : 6
how to find lable value and linkbutton value in gridview

gowthaman8870226416


Responses

Posted by: Sksamantaray on: 2/13/2012 [Member] Silver | Points: 50

Up
0
Down

Resolved
In Page_Load you can call like
Label InspectionID = (Label)grdView_InspetionNote.Rows[0].Cells[0].FindControl("LblInspectionID");
*** But ensure that your fillgridview() should be called prior to that***


In GridView1_RowDataBound you can call like:
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lbl= (Label)e.Row.FindControl("Label1");
}

Thanks,
Sanjay

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

Posted by: Pradeepkumar417 on: 2/13/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi,

In which event you have written this code.? you have to place this code in gridview rowcommand event and also you have to give commandname to linkbutton in source code.


protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)

{
if (e.CommandName.Equals("Preview"))
{


GridViewRow valu = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
int RowIndex = valu.RowIndex;

Label value = (Label)GridView1.Rows[RowIndex].FindControl("labelid");
string imgFront = value.Text;
}
}


Thanks & Regards,
Software Engineer,
Pradeep Kumar

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

Posted by: Pradeepkumar417 on: 2/13/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

You can find the label value in gridview like below.

GridViewRow val = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
int RowIndex = val.RowIndex;
Label value = (Label)GridView1.Rows[RowIndex].FindControl("labelid");




Thanks & Regards,
Software Engineer,
Pradeep Kumar

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

Posted by: Blessyjees on: 2/13/2012 [Member] Bronze | Points: 25

Up
0
Down
hi,

you can use find control to get the corresponding control and take normal attributes to get value like above post.


Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

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

Posted by: Gow.net on: 2/13/2012 [Member] Starter | Points: 25

Up
0
Down
hi Pradeepkumar417 sir
apply your code in my application i get following error sir please help me

Error 23 'System.EventArgs' does not contain a definition for 'CommandSource' and no extension method 'CommandSource' accepting a first argument of type 'System.EventArgs' could be found (are you missing a using directive or an assembly reference?)
Error 24 'System.Web.UI.WebControls.GridViewRow' does not contain a definition for 'Rows' \




gowthaman8870226416

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

Posted by: Mayankjain0035 on: 7/26/2013 [Member] Starter | Points: 25

Up
0
Down
GridViewRow val = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
int RowIndex = val.RowIndex;
Label value = (Label)GridView1.Rows[RowIndex].FindControl("labelid");

sir i used this code in button click event ,if i click the button than the value of label must be copied in different table
but there is red underline below CommandSource so Please help me what do you mean by that word or i should write these code in another method

ThankYou

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

Login to post response