2012-07-03 29 views
0

我在用戶控件GridView和動態添加使用佔位符 的控制現在我發現從電網給它控制未在電網 代碼存在的控件是如下:查找動態添加控件從GridView的在SharePoint

foreach (GridViewRow row in GridView1.Rows) 
{ 
PlaceHolder plc = (PlaceHolder)row.FindControl("lblPlaceHolder"); 
TextBox txtTextBox1 = plc.FindControl("txtTextBox1") as TextBox; //its give Null 
} 

任何人都可以有答案PLZ


增加從評論代碼:

foreach (GridViewRow dr in GridView1.Rows) 
{ PlaceHolder placeHolder = dr.FindControl("lblPlaceHolder") as PlaceHolder; 
    TextBox txtTextBox1= new TextBox(); 
    txtTextBox1.Width = 300; 
    placeHolder.Controls.Add(txtTextBox1); 
} 
+0

謝謝你先生,我已經試過這個,但仍然給零值 –

+0

好吧,plc有一個值或它是否也是? –

+0

plc的值不爲空 –

回答

0

刪除佔位符,你可以找到你的控件

,也找到了使用onRowDatabound,或從電網onRowCreated事件的控制。


BTW:爲什麼你的佔位符稱爲lblPlaceHolder,你在那裏有一個標籤,也許你是問錯了控逆變找到歲文本框,這就是爲什麼你得到一個空

void GridView_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
    GridViewRow row = e.Row as GridViewRow; 
    if (row != null) 
    { 

    TableCell myCell = row.Cells[0] as TableCell 
    TextBox txtTextBox1= new TextBox(); 
    txtTextBox1.Width = 300; 
    myCell.Controls.Add(txtTextBox1); 

    } 
} 
+0

我在佔位符中動態地添加了控件,我如何在沒有佔位符的情況下在gridview中動態添加控件? –

+0

With Row.Controls.Add – JohnnBlade

+0

不,它只是一個名稱lblPlaceHolder thare是佔位符中的文本框,我動態添加了它,並且我也在輸出中獲取它,但是當我想要獲取按鈕時,請單擊它的null null –