Click here to Skip to main content
Rate this: bad
good
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 HeaderText="Paper Title" HeaderStyle-ForeColor="IndianRed">
                <itemtemplate>
                    <%# Eval("papertitle")%>
                </itemtemplate>
            
 
            <asp:TemplateField HeaderText="Author Name" HeaderStyle-ForeColor="IndianRed" >
                <itemtemplate>
                    <%# Eval("author") %>
                </itemtemplate>
            
 
            <asp:TemplateField HeaderText="Author's Email ID" HeaderStyle-ForeColor="IndianRed">
                <itemtemplate>
                    <%# Eval("email") %>
                </itemtemplate>
            
 
            <asp:TemplateField HeaderText="Journal" HeaderStyle-ForeColor="IndianRed">
                <itemtemplate>
                    <%# Eval("attachResearchPaper")%>
                </itemtemplate>
            
 
            <asp:TemplateField HeaderText="Download" HeaderStyle-ForeColor="IndianRed">
                <itemtemplate>
                    <asp:LinkButton ID="lnkdwn" runat="server" CommandName="download" CommandArgument='<%# Eval("FilePath") %>' Text="Download" OnClick="DownloadFile">
                </itemtemplate>
            
 
            <asp:TemplateField HeaderText="Auto Generated ID" HeaderStyle-ForeColor="IndianRed">
                <itemtemplate>
                    <%# Eval("autogenID")%>
                </itemtemplate>
            
 

            <asp:TemplateField HeaderText="Admin Comment" Visible="true">
                <itemtemplate>
                    <%# Eval("Admin_Comment")%>
                </itemtemplate>
 
                <edititemtemplate>
                    <asp:TextBox ID="t1" runat="server" Text='<%# Eval("Admin_Comment") %>'>
                </edititemtemplate>
            
 

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

 
            <asp:TemplateField HeaderText="Assign_To" Visible="true" >
                <itemtemplate>
                   <asp:Label runat="server" ID="LL1" Visible="true" Text='<%# Eval("assign_TO") %>'>
 
                </itemtemplate>
 
                <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
 
                
            </edititemtemplate>
            
 

 
            <asp:TemplateField HeaderText="Assigned On Date" Visible="true" >
                <itemtemplate>
                    <%# Eval("Assigned_On_Date")%>
                </itemtemplate>
            
 
            <asp:CommandField HeaderText="EDIT" CancelText="CANCEL" EditText="EDIT" ShowEditButton="true" ShowCancelButton="true"  /> 
 
         </columns>
 


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;
            }
 

        //}
    }
}
 

this is my stored procedure used..
 
ALTER proc [dbo].[select_grid_demo]
as
select Submit_Journal.ID,Submit_Journal.papertitle,author,email,attachResearchPaper,filepath,autogenID,Admin_Comment,A_Assigned_To,ApprovedORrejected,Assigned_On_Date,Assign_To.assign_TO from Submit_Journal, Admin_Added_Details, Assign_To where Admin_Added_Details.ID=Submit_Journal.ID
 

While row updating in grid view, when i select the value from dropdown "drpAssign_to" and when i click on update, the selected value is not gets updated..
 
Please help..
Posted 23-Dec-12 4:52am
Edited 23-Dec-12 8:09am
ridoy51.7K
v2
Comments
Md. Humayun Rashed at 23-Dec-12 11:52am
   
first format your code. second, if you wanna provide large code then please, provide all the link, procedure, method. I am tried with your code. there are many errors and I did not reached your actual problem. the others error is much.
 
thanks.

1 solution

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

Solution 1

Try to find the control with its Cell index or name as below:
 
string assgnTO;
 
DropDownList drdList;

drdList = (DropDownList)(grd1.Rows[ e.RowIndex ].Cells[9].FindControl( "drpAssign_to" ));
 
assgnTO = drdList.SelectedItem.Value;
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 383
1 ChauhanAjay 186
2 Richard Deeming 180
3 Sergey Alexandrovich Kryukov 171
4 Yogesh Kumar Tyagi 165
0 Sergey Alexandrovich Kryukov 6,252
1 OriginalGriff 5,498
2 CPallini 2,473
3 Richard MacCutchan 1,627
4 Abhinav S 1,530


Advertise | Privacy | Mobile
Web03 | 2.8.140821.2 | Last Updated 24 Dec 2012
Copyright © CodeProject, 1999-2014
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