Click here to Skip to main content
12,633,990 members (24,353 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
<asp:GridView ID="grd1" runat="server" AutoGenerateColumns="false" Width="100%"
            ForeColor="WhiteSmoke" DataKeyNames="ID" onrowediting="grd1_RowEditing"
            onrowupdating="grd1_RowUpdating"
            onrowcancelingedit="grd1_RowCancelingEdit"
            onrowdatabound="grd1_RowDataBound">
            <Columns>
                <asp:TemplateField HeaderText="ID" ItemStyle-ForeColor="Aqua" HeaderStyle-ForeColor="IndianRed">
                    <ItemTemplate>
                        <%# Eval("ID") %>
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Paper Title" HeaderStyle-ForeColor="IndianRed">
                    <ItemTemplate>
                        <%# Eval("papertitle")%>
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Author Name" HeaderStyle-ForeColor="IndianRed" >
                    <ItemTemplate>
                        <%# Eval("author") %>
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Author's Email ID" HeaderStyle-ForeColor="IndianRed">
                    <ItemTemplate>
                        <%# Eval("email") %>
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Journal" HeaderStyle-ForeColor="IndianRed">
                    <ItemTemplate>
                        <%# Eval("attachResearchPaper")%>
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Download" HeaderStyle-ForeColor="IndianRed">
                    <ItemTemplate>
                        <asp:LinkButton ID="lnkdwn" runat="server" CommandName="download" CommandArgument='<%# Eval("FilePath") %>' Text="Download" OnClick="DownloadFile"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Auto Generated ID" HeaderStyle-ForeColor="IndianRed">
                    <ItemTemplate>
                        <%# Eval("autogenID")%>
                    </ItemTemplate>
                </asp:TemplateField>


                <asp:TemplateField HeaderText="Admin Comment" Visible="true">
                    <ItemTemplate>
                        <%# Eval("Admin_Comment")%>
                    </ItemTemplate>

                    <EditItemTemplate>
                        <asp:TextBox ID="t1" runat="server" Text='<%# Eval("Admin_Comment") %>'></asp:TextBox>
                    </EditItemTemplate>
                </asp:TemplateField>


                <asp:TemplateField HeaderText="Approved Or Rejected" Visible="true" >
                    <ItemTemplate>
                       <asp:Label runat="server" ID="LL0" Visible="true" Text='<%# Eval("ApprovedORrejected") %>'></asp:Label>

                    </ItemTemplate>

                    <EditItemTemplate>
                    <asp:Label runat="server" ID="LL0" Visible="false" Text='<%# Eval("ApprovedORrejected") %>'></asp:Label>
                    <asp:DropDownList runat="server" ID="drpAOR_1">

                    </asp:DropDownList>
                </EditItemTemplate>
                </asp:TemplateField>



                <asp:TemplateField HeaderText="Assign_To" Visible="true" >
                    <ItemTemplate>
                       <asp:Label runat="server" ID="LL1" Visible="true" Text='<%# Eval("assign_TO") %>'></asp:Label>

                    </ItemTemplate>

                    <EditItemTemplate>
                    <asp:Label runat="server" ID="LL1" Visible="false" Text='<%# Eval("assign_TO") %>'></asp:Label>
                    <asp:DropDownList runat="server" ID="drpAssign_to">
                        <asp:ListItem Selected="True" Text="Select" Value="Select">Select</asp:ListItem>

                    </asp:DropDownList>
                </EditItemTemplate>
                </asp:TemplateField>



                <asp:TemplateField HeaderText="Assigned On Date" Visible="true" >
                    <ItemTemplate>
                        <%# Eval("Assigned_On_Date")%>
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:CommandField HeaderText="EDIT" CancelText="CANCEL" EditText="EDIT" ShowEditButton="true" ShowCancelButton="true"  />

             </Columns>


        </asp:GridView>




protected void bind_grd1()
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["constring"]);
        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "select_grid_demo";
        cmd.Connection = con;
        SqlDataAdapter sda = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        sda.Fill(ds);
        grd1.DataSource = ds;
        grd1.DataBind();

    }
    protected void grd1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        grd1.EditIndex = e.NewEditIndex;
        bind_grd1();
    }
    protected void grd1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string admn_cmmnt=(grd1.Rows[e.RowIndex].FindControl("t1") as TextBox).Text;
        string assgnTO = (grd1.Rows[e.RowIndex].FindControl("drpAssign_to") as DropDownList).SelectedItem.Value;
        string aprORrjct = (grd1.Rows[e.RowIndex].FindControl("drpAOR_1") as DropDownList).SelectedItem.Value;
        string j_ID = grd1.DataKeys[e.RowIndex].Value.ToString();
        string strConnString = ConfigurationManager.AppSettings["constring"];
        //string strConnString = ConfigurationManager.ConnectionStrings["constring"].ConnectionString;
        using (SqlConnection con1 = new SqlConnection(strConnString))
        {
            string query1 = "update Admin_Added_Details set Admin_Comment=@Admin_Comment1,A_Assigned_To=@A_Assigned_To1,ApprovedORrejected=@ApprovedORrejected1 where ID=@ID1";
            using (SqlCommand cmd2 = new SqlCommand(query1))
            {
                cmd2.Connection = con1;
                cmd2.Parameters.AddWithValue("@Admin_Comment1", admn_cmmnt);
                cmd2.Parameters.AddWithValue("@A_Assigned_To1", assgnTO);
                cmd2.Parameters.AddWithValue("@ApprovedORrejected1",aprORrjct);
                cmd2.Parameters.AddWithValue("@ID1",j_ID);
                con1.Open();
                cmd2.ExecuteNonQuery();
                con1.Close();
            }
        }
          
        grd1.EditIndex = -1;
        bind_grd1();
    }
    
    protected void grd1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        grd1.EditIndex = -1;
        bind_grd1();
    }




    protected void grd1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow && grd1.EditIndex==e.Row.RowIndex)
        {
                DropDownList ddrrpp = (DropDownList)e.Row.FindControl("drpAOR_1");
                string query = "select ApprovedORrejected from approved_OR_rejected ";
                SqlCommand cmd2 = new SqlCommand(query);
                ddrrpp.DataSource = GetData(cmd2);
                ddrrpp.DataTextField = "ApprovedORrejected";
                ddrrpp.DataValueField = "ApprovedORrejected"; 
                ddrrpp.DataBind();
                Label lb = (e.Row.FindControl("LL0") as Label);
                if (lb != null)
                {
                    ListItem dd = ddrrpp.Items.FindByValue((e.Row.FindControl("LL0") as Label).Text);
                    if (dd != null)
                    {
                        dd.Selected = true;
                    }
                }
                //ddrrpp.Items.FindByValue((e.Row.FindControl("LL0") as Label).Text).Selected = true;
                 
            }


        if (e.Row.RowType == DataControlRowType.DataRow && grd1.EditIndex == e.Row.RowIndex)
        {
            DropDownList ddrrpp1 = (DropDownList)e.Row.FindControl("drpAssign_to");
            string query = "select U_Name from Add_New_User ";
            SqlCommand cmd3 = new SqlCommand(query);
            ddrrpp1.DataSource = GetData(cmd3);
            ddrrpp1.DataTextField = "U_Name";
            ddrrpp1.DataValueField = "U_Name";
            ddrrpp1.DataBind();
            Label lb = (e.Row.FindControl("LL1") as Label);
            if (lb != null)
            {
                ListItem dd1 = ddrrpp1.Items.FindByValue((e.Row.FindControl("LL1") as Label).Text);
                if (dd1 != null)
                {
                    dd1.Selected = true;
                }
            }
            //ddrrpp.Items.FindByValue((e.Row.FindControl("LL0") as Label).Text).Selected = true;

        }


        
    }


    private DataTable GetData(SqlCommand cmd2)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["constring"]);
        //string strr = ConfigurationManager.ConnectionStrings["constring"].ConnectionString;
        //using (SqlConnection conn = new SqlConnection(strr))
        //{
            using (SqlDataAdapter ssda = new SqlDataAdapter())
            {
                cmd2.Connection = con;
                ssda.SelectCommand = cmd2;
                using (DataTable ddt = new DataTable())
                {
                    ssda.Fill(ddt);
                    return ddt;
                }
             //}
        }
    }

while row updating, cant update column "assign_TO"...

Please help..
Posted 23-Dec-12 3:57am
Updated 23-Dec-12 3:58am
ProgramFOX189.4K
v2
Comments
Abhishek Pant 23-Dec-12 9:16am
   
I can't find any column assign_TO in your server side code but its drpAssign_to is there.So If you haven't wrote code for it then how will it work?
purohitritika 23-Dec-12 9:21am
   
<asp:TemplateField HeaderText="Assign_To" Visible="true" >
<itemtemplate>
<asp:Label runat="server" ID="LL1" Visible="true" Text='<%# Eval("assign_TO") %>'>



<edititemtemplate>
<asp:Label runat="server" ID="LL1" Visible="false" Text='<%# Eval("assign_TO") %>'>
<asp:DropDownList runat="server" ID="drpAssign_to">
<asp:ListItem Selected="True" Text="Select" Value="Select">Select






this is my assign_TO column.. <%# Eval("assign_TO") %>
HariPrasad katakam 3-Jan-13 3:18am
   
Can you please elaborate your problem. i mean
Are you able to update the other column values like admn_cmmnt , aprORrjct values?? or entire row values are not getting updated??

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Should't it be U_Name and not assign_TO
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161208.2 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100