2012-08-30 69 views
1

我使用GridView空數據源進行批量插入,我將如何預先填充實例列A的下拉框的值?到目前爲止,我有以下,但它不工作預填充gridview空數據源

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
    if (e.Row.RowType == DataControlRowType.DataRow) 
    { 
     TextBox tb = (TextBox)e.Row.FindControl("YourTextBoxID"); 
     if(tb != null) 
     { 
      tb.Text = DropDownList1.SelectedItem.Text; 
     } 
    } 
} 
+0

什麼樣_empty_ DataSorce的?如果它是空的,RowDataBound.DatRow如何被解僱? –

+0

templatefields與文本框....我使用錯誤的事件? – EM90210

回答

0

我不明白你的意思數據源是什麼。我假設你的意思是一個自動填充默認值的DataSource。

你可以使用一個DataTable

var tbl = new DataTable(); 
tbl.Columns.Add("ColumnA"); 
var defText = DropDownList1.SelectedItem.Text; 
for(int i = 0; i < 1000; i++) 
{ 
    tbl.Rows.Add(defText); 
} 
GridView1.DataSource = tbl; 
GridView1.DataBind();