Jambukiya Anil

Jambukiya Anil

  • NA
  • 130
  • 693

not delete record in gridview

Apr 19 2016 4:12 AM

 
gridview
 
<asp:GridView ID="SentBoxGridView" CssClass="footable" Width="100%" runat="server" AutoGenerateColumns="False" onrowdatabound="SentBoxGridView_RowDataBound"
onpageindexchanging="SentBoxGridView_PageIndexChanging" PageSize="1" OnRowDeleting="SentBoxGridView_RowDeleting">
<Columns>
<asp:TemplateField>
<ItemTemplate >
<asp:LinkButton ID="lbtnreply" runat="server" onclick="lbtnreply_Click"
ValidationGroup='<%# Eval("MessageId") %>' OnClientClick="document.getElementById('form1').target ='_self';">Reply</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible=false>
<ItemTemplate>
<asp:Label id="lblmessageid" runat ="server" text='<%# Eval("MessageId")%>'></asp:Label>
<asp:Label id="lblAddressId" runat ="server" text='<%# Eval("MessageStatusId")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="FromName" HeaderText="From"
SortExpression="FromName"/>
<asp:BoundField DataField="MessageBody" HeaderText="Message"
SortExpression="MessageBody" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
 
 
 
 
code behind file 
 
protected void SentBoxGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
GridViewRow row = SentBoxGridView.Rows[e.RowIndex];

TextBox MessageId = (TextBox)row.FindControl("MessageId");
SqlConnection con;

con = new SqlConnection(ConfigurationManager.ConnectionStrings["SAVARIConnectionString5"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("delete from Messages where MessageId='" + MessageId + "'", con);
cmd.ExecuteNonQuery();
con.Close();

}

 

Answers (1)