Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
  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"));
        
  }

Need help as I am confused how to do?plz help..
Posted
Updated 19-Aug-13 1:32am
v2
Comments
CodeBlack 19-Aug-13 7:37am    
Why do you bind your drop down list in RowEditing event as it is going to bind the same list for the same drop down? Better you bind it in page load event.
Member 10218129 19-Aug-13 8:37am    
Thanks,I hv done it before,but it cann't improvise the result ,it is same as before..How to do the inline editing for the drop downlist,i want to display the value from the database to the dropdown list
CodeBlack 19-Aug-13 8:58am    
where is your dropdown list ? inside grid or outside grid ?

1 solution

C#
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
 
Share this answer
 
v4
Comments
Member 10218129 20-Aug-13 1:59am    
Thanks for ur attention ,I hv tried this code but i got the exception msg"Object reference not set to an instance of an object." & still i couldn't find the list in drop downbox
S.P.Tiwari 20-Aug-13 2:50am    
you are getting control ddl. or its comming null ..?
S.P.Tiwari 20-Aug-13 2:53am    
now check with the updated solution you are getting control null or not. if its not null then you have problem with your binding.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900