TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jambukiya Anil
NA
130
701
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();
}
Reply
Answers (
1
)
How to create url rewriting in asp.net?
Convert GridView Columns to Rows frm the sql tble saved data