且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

数据绑定的DropDownList的GridView的EditItemTemplate里面

更新时间:2023-10-07 09:47:52

试试这个。

protected void gvEmp_RowEditing(object sender, GridViewEditEventArgs e)
{
    DemoGrid.EditIndex = e.NewEditIndex;
    BindGrid();
    DropDownList dropdown = gvEmp.Rows[e.NewEditIndex].FindControl("DropDownList1") as DropDownList;
    BindDropDown(dropdown);
}

private void BindDropDown(DropDownList temp)
{
    string connectionString = "Password=priyal;User ID=priyal;Initial Catalog=asptest;Data Source=dbsvr";
    string query = "select deptno from employees";
    DataSet dataset = new DataSet("Employees");
    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        using (SqlDataAdapter adapter = new SqlDataAdapter(query, connection))
        {
            adapter.Fill(dataset);
        }
    }

    temp.DataSource = dataset;
    temp.DataTextField = "deptno";
    temp.DataValueField = "deptno";
    temp.DataBind();
}

除非你通过行的DropDownList 作为参数,如何将你的 BindDropDown 识别哪些 DropDownList的绑定到?

Unless you pass the rows DropDownList as a parameter, how would your BindDropDown recognize which DropDownList to bind to?