<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"];
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;
}
}
}
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;
}
}
}
}
private DataTable GetData(SqlCommand cmd2)
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["constring"]);
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..