如何在rowediting中将数据绑定到数据库中的下拉列表 [英] How to bind data to a dropdownlist from database in rowediting

查看:106
本文介绍了如何在rowediting中将数据绑定到数据库中的下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想在网格视图中填充一个下拉列表,在编辑时我想要选择更新的值列表。我在存储过程的帮助下完成了它我创造了&已经在我的项目中使用但它没有完全正常工作。这是下面的C#代码;

//这是用于RowEditing

Hi All,
I want to populate a drop-downlist in the grid view, when editing i want the list of values to select for update.I hv done it with the help of stored procedure that i hv created & used already in my project but it is not working exactly. here is the piece of C# code below;
//This is for RowEditing

  protected void taskgrid_RowEditing(object sender, GridViewEditEventArgs e)
    {
        Load_Projectlist();
        taskgrid.EditIndex = e.NewEditIndex;
        BindTaskList();
    }
//This is for RowUpdating
protected void taskgrid_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int UserID = UDFLib.ConvertToInteger(Session["USERID"]); 

        
        int PIC = UDFLib.ConvertToInteger((taskgrid.Rows[e.RowIndex].FindControl("ddlPIC") as DropDownList).SelectedValue);
       
        int ProjectID = UDFLib.ConvertToInteger((taskgrid.Rows[e.RowIndex].FindControl("ddlprojectlist")as  DropDownList).SelectedValue);
        int ModuleID = UDFLib.ConvertToInteger((taskgrid.Rows[e.RowIndex].FindControl("ddlmodulelist")as DropDownList).SelectedValue);

        int result = UserTaskProgress.Update_Task( UserID, ProjectID, ModuleID, PIC);
        if (result == 1)
        {
            taskgrid.EditIndex = -1;
            BindTaskList();
            grdresult.Text = "Task updated successfully";

        }
    }
//This is to load the project list
private void Load_Projectlist()
    {
        DataTable dtpl =   UserTaskProgress.Get_ProjectList(UDFLib.ConvertToInteger(Session["USERID"]));
        ddlnewproject.DataSource = dtpl;
        ddlnewproject.DataBind();
        ddlnewproject.Items.Insert(0,new ListItem("-Select-","0"));
        
  }



需要帮助,因为我很困惑怎么办?plz help ..


Need help as I am confused how to do?plz help..

推荐答案

protected void taskgrid_RowEditing(object sender, GridViewEditEventArgs e)
    {
        Load_Projectlist();
        taskgrid.EditIndex = e.NewEditIndex;
        BindTaskList();
    //here you will get the dropdown list
        DropDownList ddl = taskgrid.Rows[e.NewEditIndex].FindControl("ddlnewproject") as DropDownList;

//now provide the datasource to dropdown and bind here
//write code here for binding

if(ddl != null)
{
 DataTable dtpl =   UserTaskProgress.Get_ProjectList(UDFLib.ConvertToInteger(Session["USERID"]));
        ddl .DataSource = dtpl;
        ddl .DataBind();
        ddl .Items.Insert(0,new ListItem("-Select-","0"));
    }
}
else
{

// control not found
}







希望这会有所帮助




hope this will help


这篇关于如何在rowediting中将数据绑定到数据库中的下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆