views:

33

answers:

0

I'm using gridview control to edit the response given by the admin to query raised by the users. When the admin reaches the query admin page, all queries need to be displayed in an editable grid. There are calendar controls and a Query Status filter on the page, which once selected shall filter the records and present the filtered records in an editable grid. To achieve this I'm using two grid view controls. the one which gets filled on page_load and the other one that shows the filtered result.

However, editing is not working for the first gridview( page_load one).... Insight: onRowCommand. the e.commandName =="Update" event contains the old values...

Code for the grid that shows filtered records...

protected void gvAllAdminSQueries_onRowEditing(object sender, GridViewEditEventArgs e) { string dtestarttime = DatePicker1.SelectedDate.ToString(); string dteenddate = DatePicker2.SelectedDate.ToString(); txtStart.Text = dtestarttime; txtEnd.Text = dteenddate;

    gvAllAdminSQueries.EditIndex = e.NewEditIndex;
    if (Session["Role"].ToString() == "Admin")
        role = "Admin";
    else if (Session["Role"].ToString() == "R&R")
        role = "R&R";
    else if (Session["Role"].ToString() == "Travel")
        role = "Travel";
    else if (Session["Role"].ToString() == "FACE")
        role = "FACE";
    else if (Session["Role"].ToString() == "HR")
        role = "HR";
    else if (Session["Role"].ToString() == "Tech Forum")
        role = "Tech Forum";
    else if (Session["Role"].ToString() == "LOB")
        role = "LOB";
    else
    {
        Response.Redirect("WelcomePage.aspx");
    }
    DataSet ds = new QueriesBLL().GetAllAdminSQueries(Convert.ToInt32(Session["EmployeeId"]), role,txtStart.Text,txtEnd.Text,Convert.ToInt32(ddListQueryStatus.SelectedValue));

    gvAllAdminSQueries.DataSource = ds;
    gvAllAdminSQueries.DataBind();
    int index = Convert.ToInt32(e.NewEditIndex);
    GridViewRow row = gvAllAdminSQueries.Rows[index];
    ((DropDownList)row.FindControl("ddQueryStatus")).Enabled = true;
    gvAllAdminSQueries.Visible = true;
}

protected void gvAllAdminSQueries_RowCommand(object sender, GridViewCommandEventArgs e)
{
    int Queryno = 0;
    int intQueryStatusId=9;
    string response;
    int QueryX;        

       if (e.CommandName =="Edit")
        {
            int index = Convert.ToInt32(e.CommandArgument);
            GridViewRow row = gvAllAdminSQueries.Rows[index];
            ((DropDownList)row.FindControl("ddQueryStatus")).Enabled = true;
           //foreach (GridViewRow gvRow in gvAllAdminSQueries.Rows)
           // {
           //     (((DropDownList)gvRow.FindControl("ddQueryStatus")).Enabled) = true;
           // }
        }


    if (e.CommandName == "Update")
    {

        GridView AttribGrd = ((System.Web.UI.Control)(e.CommandSource)).BindingContainer.NamingContainer as GridView;

        Queryno = Convert.ToInt32(AttribGrd.Rows[Convert.ToInt32(e.CommandArgument)].Cells[2].Text);
        //response = ((TextBox)(AttribGrd.Rows[Convert.ToInt32(e.CommandArgument)].Cells[8].Controls[0])).Text;                        
        response = ((TextBox)AttribGrd.Rows[Convert.ToInt16(e.CommandArgument)].Cells[9].FindControl("txtResponse")).Text;
        //response = objRowView.Row["intProductImageId"].ToString();
        foreach (GridViewRow gvRow in gvAllAdminSQueries.Rows)
        {

            QueryX = Convert.ToInt32(gvRow.Cells[2].Text);
            if (Queryno == QueryX)
            {
                intQueryStatusId = Convert.ToInt32(((DropDownList)gvRow.FindControl("ddQueryStatus")).SelectedValue);
                break;
            }
        }

        //intQueryStatusId = Convert.ToInt32(((DropDownList)(AttribGrd.Rows[Convert.ToInt32(e.CommandArgument)].Cells[6].Controls[0])).DataValueField);
        //intQueryStatusId = Convert.ToInt32(AttribGrd.Rows[Convert.ToInt32(e.CommandArgument)].Cells[6]);

        QueriesBLL obj = new QueriesBLL();
        obj.UpdateAllAdminSQuery(Queryno, response, intQueryStatusId);

        gvAllAdminSQueries.EditIndex = -1;


        Response.Redirect("Querymanagement.aspx");
    }
    if (e.CommandName == "Cancel")
    {
        Response.Redirect("Querymanagement.aspx");
    }


}