<asp:UpdatePanel ID="upl" runat="server"> <Triggers> <asp:AsyncPostBackTrigger ControlID="btnSearch" EventName="serverclick" /> <asp:AsyncPostBackTrigger ControlID="GvGrade" /> </Triggers> <ContentTemplate> <asp:GridView ID="GvGrade" runat="server" AutoGenerateColumns="false" ClientIDMode="Static"> <Columns> <asp:TemplateField HeaderText="Task ID" HeaderStyle-HorizontalAlign="Center"> <HeaderStyle Width="100" BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <ItemStyle HorizontalAlign="Center" /> <ItemTemplate> <asp:Label ID="lblID" CssClass="lblID" runat="server" Text='<%# Eval("drug_id") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> <Columns> <asp:TemplateField HeaderText="Drug Name" HeaderStyle-HorizontalAlign="Center"> <HeaderStyle Width="300" BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <ItemStyle HorizontalAlign="Center" /> <ItemTemplate> <asp:Label ID="lblDrugName" CssClass="lblImageName" runat="server" Text='<%# Eval("drug_name") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> <Columns> <asp:TemplateField HeaderText="Drug Description" HeaderStyle-HorizontalAlign="Center"> <HeaderStyle Width="500" BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <ItemStyle HorizontalAlign="Center" /> <ItemTemplate> <asp:Label ID="lblDrugDescription" CssClass="lblImage" runat="server" Text='<%# Eval("drug_description") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> <Columns> <asp:TemplateField HeaderText="Task Status" HeaderStyle-HorizontalAlign="Center"> <HeaderStyle Width="200" BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <ItemStyle HorizontalAlign="Center" /> <ItemTemplate> <asp:Label ID="lblTaskStatus" CssClass="lblImage" runat="server" Text='<%# Eval("task_status") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> <Columns> <asp:TemplateField HeaderText="Task Type" HeaderStyle-HorizontalAlign="Center"> <HeaderStyle Width="100" BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <ItemStyle HorizontalAlign="Center" /> <ItemTemplate> <asp:Label ID="lblTaskType" CssClass="lblImage" runat="server" Text='<%# Eval("task_type") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> <Columns> <asp:TemplateField HeaderText="Delete Tasks" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Center"> <HeaderStyle Width="100" BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <ItemStyle HorizontalAlign="Center" /> <ItemTemplate> <asp:CheckBox ID="chkbox" runat="server" onclick="javascript:HighlightRow(this);" /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </ContentTemplate> </asp:UpdatePanel>
protected void showData() { SqlDataAdapter da = new SqlDataAdapter("select * from Drug", con); DataSet ds = new DataSet(); da.Fill(ds); GvGrade.DataSource = ds; GvGrade.DataBind(); } protected void DeleteRecord(string drug_name) { SqlConnection con = new SqlConnection(cs); SqlCommand com = new SqlCommand("delete from Drug where drug_name=@ID", con); com.Parameters.AddWithValue("@ID", drug_name); con.Open(); com.ExecuteNonQuery(); con.Close(); } protected void BtnLogin_Click(object sender, EventArgs e) { foreach (GridViewRow grow in GvGrade.Rows) { CheckBox chkbox = (CheckBox)grow.FindControl("chkbox"); if (chkbox.Checked) { string drug_name = grow.Cells[1].Text; DeleteRecord(drug_name); } } //Displaying the Data in GridView showData(); }
<asp:ScriptManager ID="ScriptManager1" runat="server"> <asp:UpdatePanel ID="upl" runat="server"> <triggers> <asp:AsyncPostBackTrigger ControlID="GvGrade" /> <asp:AsyncPostBackTrigger ControlID="BtnRegister" /> <contenttemplate> <asp:Button ID="BtnRegister" runat="server" class="btn btn-info" Text="Delete" OnClick="BtnLogin_Click" /> <asp:GridView ID="GvGrade" runat="server" AutoGenerateColumns="false" ClientIDMode="Static"> <columns> <asp:TemplateField HeaderText="Task ID" HeaderStyle-HorizontalAlign="Center"> <HeaderStyle Width="100" BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <ItemStyle HorizontalAlign="Center" /> <itemtemplate> <asp:Label ID="lblID" CssClass="lblID" runat="server" Text='<%# Eval("drug_id") %>'> <columns> <asp:TemplateField HeaderText="Drug Name" HeaderStyle-HorizontalAlign="Center"> <HeaderStyle Width="300" BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <ItemStyle HorizontalAlign="Center" /> <itemtemplate> <asp:Label ID="lblDrugName" CssClass="lblImageName" runat="server" Text='<%# Eval("drug_name") %>'> <columns> <asp:TemplateField HeaderText="Drug Description" HeaderStyle-HorizontalAlign="Center"> <HeaderStyle Width="500" BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <ItemStyle HorizontalAlign="Center" /> <itemtemplate> <asp:Label ID="lblDrugDescription" CssClass="lblImage" runat="server" Text='<%# Eval("drug_description") %>'> <columns> <asp:TemplateField HeaderText="Task Status" HeaderStyle-HorizontalAlign="Center"> <HeaderStyle Width="200" BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <ItemStyle HorizontalAlign="Center" /> <itemtemplate> <asp:Label ID="lblTaskStatus" CssClass="lblImage" runat="server" Text='<%# Eval("task_status") %>'> <columns> <asp:TemplateField HeaderText="Task Type" HeaderStyle-HorizontalAlign="Center"> <HeaderStyle Width="100" BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <ItemStyle HorizontalAlign="Center" /> <itemtemplate> <asp:Label ID="lblTaskType" CssClass="lblImage" runat="server" Text='<%# Eval("task_type") %>'> <columns> <asp:TemplateField HeaderText="Delete Tasks" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Center"> <HeaderStyle Width="100" BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <ItemStyle HorizontalAlign="Center" /> <itemtemplate> <asp:CheckBox ID="chkbox" runat="server" />
public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { showData(); } } protected void showData() { DataTable ds = new DataTable(); ds.Columns.Add("drug_id"); ds.Columns.Add("drug_name"); ds.Columns.Add("drug_description"); ds.Columns.Add("task_status"); ds.Columns.Add("task_type"); ds.Rows.Add(1, "a", "aaa", "aaaa", "aaaaaaaaaaaa"); ds.Rows.Add(2, "b", "bb", "bbb", "bbbbbbbbbbbb"); ds.Rows.Add(3, "ac", "cc", "ccc", "ccccccccccc"); ds.Rows.Add(4, "d", "dd", "ddddd", "dddddddddddddd"); GvGrade.DataSource = ds; GvGrade.DataBind(); } protected void DeleteRecord(string drug_name) { } protected void BtnLogin_Click(object sender, EventArgs e) { foreach (GridViewRow grow in GvGrade.Rows) { CheckBox chkbox = (CheckBox)grow.FindControl("chkbox"); if (chkbox.Checked) { string drug_name = grow.Cells[1].Text; DeleteRecord(drug_name); } } //Displaying the Data in GridView showData(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)