Thursday, September 12, 2013

Capturing Template field values of editable Gridview

I was capturing the values from the grid view . i could do it oretty easily but what struck me was how do i capture values of a template field in editable grid view. it was returning null.
so here is what I did

a)Use find control method with rowdatabound() event.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lbl= e.Row.FindControl("Tenant_Name") as Label;
               
            }

}

b)in the Rowcommand()event i looped through each row . and at specified row index i captured the desired value a below:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
               string str= GridView1.Rows[i].Cells[1].Text;
            }
        }

here is the screenshot


No comments:

Post a Comment