Hi,
I am new to C# and seeking for the assistance.
Problem is,
I have an Add, Edit, Delete button and a gridview. What i want is when I
click the Add button I should not able to select row in gridview.
Gridview should look like disabled.
Here is my codes in gridview row created event.
if (e.Row.RowType == DataControlRowType.DataRow)
{
//e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';";
//e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
e.Row.Attributes.Add("onclick",
Page.ClientScript.GetPostBackEventReference((Control)sender, "Select$" +
e.Row.RowIndex.ToString()));
}
thanks,
Dynamically Disable row selection in GridView
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

happy happy9 reputationPosted Nov 29, 2010, 6:40 PM EST
Actuallly I dint understand your problem. But anyhow if you want to disable a row in grid dynamically, then you can easily apply styles for those particular rows dynamically in row databound. For this see below example. here i have disbled the first 3 rows. so in the head tag you can write the required styles for 'disabled' css class. if its help you,then ok. otherwise please explain your problem clearly, then it may help you to get exact reply.
protected void detailGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].CssClass = "diabled";
e.Row.Cells[1].CssClass = "diabled";
e.Row.Cells[2].CssClass = "diabled";
}
}