Tami
Tami

Reputation: 586

How to get GridViewRow from DataKeys

I know this type of question is asked before but no one got the answer yet...!!

How to get a Grid View Row from Data Keys.I don't want to iterate through the whole gird view. I want to access specific text box(s) in a grid view.

for example in a 100 rows grid view i only want to disable any 2 text boxes on Page Load. I have Data Key Names defined in grid, but how to get rows from it ? any idea?

Upvotes: 0

Views: 2135

Answers (1)

Indranil.Bharambe
Indranil.Bharambe

Reputation: 1498

Please try following code..

protected void GVSample_RowDataBound(object sender, GridViewRowEventArgs e)
{   
    //Get data row view
    DataRowView drview = e.Row.DataItem as DataRowView;
    if (e.Row.RowType == DataControlRowType.DataRow)
    {       
        //Find textbox control
        TextBox txtname = (TextBox)e.Row.FindControl("txtName");
        string Name = txtname.Text;

        if (((GridView)sender).DataKeys[e.Row.RowIndex].Value.ToString() == "Leave")
        { 
            txtname.disable=true;
        }
        else 
        { 
            txtname.disable = false; 
        }
    }
}

Upvotes: 1

Related Questions