2013-05-16 81 views
1

我有一個gridview,我想增加一列的大小在它當用戶點擊編輯鏈接按鈕使用此代碼,奇的GridView列大小

protected void RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
    if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowState == DataControlRowState.Edit) 
    { 
     // Comments 
     TextBox comments = (TextBox)e.Row.Cells[column_index].Controls[control_index]; 
     comments.TextMode = TextBoxMode.MultiLine; 
     comments.Height = 100; 
     comments.Width = 400; 
    } 
} 

問題

它的工作原理,但只適用於奇數Gridview行,並休息甚至行數保持不變,任何人都可以指導我解決方案嗎?

+1

可你是位清晰,詳細點嗎? – Sakthivel

+0

'column_index'和'control_index'的值是多少? –

+0

3和0 respectivily – Mathematics

回答

2

使用此。

//代碼

if ((e.Row.RowState == (DataControlRowState.Edit | 
DataControlRowState.Alternate)) || (e.Row.RowState == 
DataControlRowState.Edit)) 
{ 
/* Edit Mode Code Here (DataControlRowState.Edit) */ 
} 
0

您可以通過這種方式做過多

protected void RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
    if (e.Row.RowType == DataControlRowType.DataRow) 
    { 
    if ((e.Row.RowState & DataControlRowState.Edit) > 0) 
    { 
     // you code logic 
    } 
    } 
}