0
我有這個代碼,它的工作原理。但永遠需要。好的,也許是40秒,但這是永遠在線應用程序。最有效的方式來填充GridView中的DropDownLists?
protected void DataGrid_Open_RowDataBound(object sender, GridViewRowEventArgs e)
{
OracleConnection conn = GetConnection();
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView drv = e.Row.DataItem as DataRowView;
//**********************************************
//************* Auditor Names ****************
//**********************************************
OracleCommand cmd4 = new OracleCommand();
cmd4.CommandType = CommandType.StoredProcedure;
cmd4.CommandText = "CSTAPP_O.CST_AMR_AUDITORNAMES";
cmd4.Connection = conn;
cmd4.Parameters.Add("cursor_", OracleType.Cursor).Direction = ParameterDirection.Output;
var SearchAdapter4 = new OracleDataAdapter(cmd4);
var ds4 = new DataTable();
SearchAdapter4.Fill(ds4);
DataView view = new DataView(ds4);
DataTable distinctValues = new DataTable();
distinctValues = view.ToTable(true, "Auditor_Name", "AuditorID");
DropDownList ddl = e.Row.FindControl("EI_Open_AuditorName") as DropDownList;
ddl.DataSource = distinctValues;
ddl.DataTextField = "Auditor_Name";
ddl.DataValueField = "AuditorID";
ddl.DataBind();
ddl.SelectedValue = drv["Auditor_Name"].ToString();
//**********************************************
//***************** Status *******************
//**********************************************
OracleCommand cmd5 = new OracleCommand();
cmd5.CommandType = CommandType.StoredProcedure;
cmd5.CommandText = "CSTAPP_O.CST_AMR_AUDITSTATUS";
cmd5.Connection = conn;
cmd5.Parameters.Add("cursor_", OracleType.Cursor).Direction = ParameterDirection.Output;
var SearchAdapter5 = new OracleDataAdapter(cmd5);
var ds5 = new DataTable();
SearchAdapter5.Fill(ds5);
DataView view5 = new DataView(ds5);
DataTable distinctValues5 = new DataTable();
distinctValues5 = view5.ToTable(true, "StatusName", "StatusID");
// DataRowView drv = e.Row.DataItem as DataRowView;
DropDownList ddl5 = e.Row.FindControl("EI_Open_AuditStatus") as DropDownList;
ddl5.DataSource = distinctValues5;
ddl5.DataTextField = "StatusName";
ddl5.DataValueField = "StatusID";
ddl5.DataBind();
ddl5.SelectedValue = drv["Overall_Audit_Status"].ToString();
}
}
catch (Exception ex)
{
}
}
有沒有更高效的方法來做到這一點?我無法相信在GridView中爲每條記錄重新運行存儲過程是填充DropDownList的最佳方式,並且我有2個DropDownLists來填充。
我在發佈它之前大約20秒發現了這個。 :o)對於所有未來的訪問者,這種方法就像一個冠軍。 –