datalist和formview如何获取控件
kevn 2009-09-22 03:33:56 protected void DataList1_EditCommand1(object source, DataListCommandEventArgs e)
{
DataList1.EditItemIndex = e.Item.ItemIndex;
Bind();
DropDownList ClientNanme = e.Item.FindControl("ClientNanme") as DropDownList;
HiddenField hfPublisher = e.Item.FindControl("hfPublisherId") as HiddenField;
ClientNanme.SelectedValue = hfPublisher.Value.Trim();
}
为什么
DropDownList ClientNanme = e.Item.FindControl("ClientNanme") as DropDownList;
HiddenField hfPublisher = e.Item.FindControl("hfPublisherId") as HiddenField;
获取不到值?
报错未实例化,另外formview如何找到控件?
下面方法找不到
protected void FormView1_DataBound(object sender, EventArgs e)
{
string sql = "select client_id,client_name from t_client where flag = 0";
DataSet ds = Fesco.DAL.DBHelper.GetDataSet(sql);
DropDownList d = (DropDownList)FormView1.Row.FindControl("DropDownList1");
if (d != null)
{
d.DataSource = ds;
}
}