Santhonabin

Santhonabin

  • NA
  • 51
  • 212.8k

Update Event is not working properly in Grid View Control(Urgent)

May 19 2011 5:10 AM
Hi...

i didnt get any error in runtime. but updation event not working.... So Please help me to recover this problem..


Default.aspx.cs
----------------

protected void grdv_RowEditing(object sender, GridViewEditEventArgs e)
{

grdvCustomer.EditIndex = e.NewEditIndex;

bind();



}

protected void Grdv_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{

grdvCustomer.EditIndex = -1;

bind();

}



protected void grdv_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
// Response.Write("<script language='javascript'>alert( 'Updated Successfully !')</script>");

GridViewRow row = (GridViewRow)grdvCustomer.Rows[e.RowIndex];
Label lbl = (Label)row.FindControl("lblComId");

TextBox txtCmt = (TextBox)row.FindControl("txtComments");

DropDownList drpfdb = (DropDownList)row.FindControl("drpFeedback");
DropDownList drpStat = (DropDownList)row.FindControl("drpStatus");



conn.Open();
SqlCommand cmd = new SqlCommand("update compliants set status='" + drpStat.SelectedItem.Text + "',comments='" + txtCmt.Text + "' ,feedback ='" + drpfdb.SelectedItem.Text + "'where comid='" + lbl.Text + "'", conn);
cmd.ExecuteNonQuery();
grdvCustomer.EditIndex = -1;
conn.Close();


bind();



}

public void bind()
{

conn.Open();

SqlDataAdapter da = new SqlDataAdapter("select * from compliants where customerid='" + lblCusAns.Text + "' ", conn);

DataSet ds = new DataSet();

da.Fill(ds, "compliants");

grdvCustomer.DataSource = ds.Tables[0].DefaultView;

grdvCustomer.DataBind();

conn.Close();




}



protected void grdv_PageIndexChanging(object sender, GridViewPageEventArgs e)

{
grdvCustomer.PageIndex = e.NewPageIndex;

bind();
}




Source Code
-------------

<asp:GridView ID="grdvCustomer" runat="server" BackColor="White"
AllowPaging="True" AllowSorting="True"
BorderColor="#999999"
BorderStyle="Solid"
BorderWidth="1px"
CellPadding="3"
ForeColor="Black"
GridLines="Vertical"
AutoGenerateColumns="False"
OnRowEditing="grdv_RowEditing "
OnRowCancelingEdit="Grdv_RowCancelingEdit"
OnRowUpdating="grdv_RowUpdating"
OnPageIndexChanging="grdv_PageIndexChanging" >
<FooterStyle BackColor="#CCCCCC" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#CCCCCC" />
<Columns>
<asp:TemplateField HeaderText="Compliant Id" >
<ItemTemplate >
<asp:Label id="lblComId" runat ="server"><%#Eval("comid") %></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Customer Id" >
<ItemTemplate>
<asp:Label id="lblCusID" runat="server" ></asp:Label><%#Eval("customerid") %></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<ItemTemplate >
<asp:Label ID="lbldesc" runat="server" ><%#Eval("description") %></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Priority">
<ItemTemplate>
<asp:Label ID="lblPriority" runat="server" ><%#Eval("priority") %></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Status" >
<ItemTemplate>
<asp:Label ID="lblStatus" runat="server"><%#Eval("status") %></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="drpStatus" runat="server" >
<asp:ListItem Text ="New" Value="New" Selected="True"></asp:ListItem>
<asp:ListItem Text ="Assigned" Value="Assigned"></asp:ListItem>
<asp:ListItem Text ="Resolved" Value="Resolved"></asp:ListItem>
<asp:ListItem Text ="Not Resolved" Value="Not Resolved"></asp:ListItem>
<asp:ListItem Text ="Pending" Value="Pending"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Comments">
<ItemTemplate>
<asp:Label ID="lblComments" Text='<%#Eval("comments") %>' runat="server" ></asp:Label>
</ItemTemplate>
<EditItemTemplate >
<asp:TextBox ID="txtComments" Text='<%#Eval("comments") %>' runat="server"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Feedback">
<ItemTemplate >
<asp:Label id="lblfeedback" Text='<%#Eval("feedback") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate >
<asp:DropDownList ID="drpFeedback" runat="server" >
<asp:ListItem Text ="Good" Value="Good" Selected="True"></asp:ListItem>
<asp:ListItem Text ="Worst" Value="Worst"></asp:ListItem>
<asp:ListItem Text ="Not Worst" Value="Not Worst"></asp:ListItem>
<asp:ListItem Text ="Better" Value="Better"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Image" CancelImageUrl="~/cancel.png" EditImageUrl="~/notepad_(edit)_16x16.gif"
HeaderImageUrl="~/notepad_(edit)_16x16.gif" ShowEditButton="True" UpdateImageUrl="~/update1.jpg" EditText="" InsertText="" NewText="" SelectText="" />
</Columns>
</asp:GridView>



Answers (7)