Hi makumbi,
Please refer below sample.
For this sample i have refer below article. For more details refer below article link.
HTML
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<style type="text/css">
body { font-family: Arial; font-size: 10pt; }
.modalBackground { background-color: Black; filter: alpha(opacity=40); opacity: 0.4; }
.modalPopup { background-color: #FFFFFF; width: 300px; border: 3px solid #0DA9D0; }
.modalPopup .header { background-color: #2FBDF1; height: 30px; color: White; line-height: 30px; text-align: center; font-weight: bold; }
.modalPopup .body { min-height: 50px; line-height: 30px; text-align: center; padding: 5px; }
.modalPopup .footer { padding: 3px; }
.modalPopup .button { height: 23px; color: White; line-height: 23px; text-align: center; font-weight: bold; cursor: pointer; background-color: #9F9F9F; border: 1px solid #5C5C5C; }
.modalPopup td { text-align: left; }
</style>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<table cellpadding="2" class="auto-style1">
<tr>
<td class="auto-style54">
Call No
</td>
<td class="auto-style33" colspan="4">
<asp:TextBox ID="Callno" runat="server" Width="95px"></asp:TextBox>
</td>
<td class="auto-style15">
Entry Code
</td>
<td class="auto-style15" colspan="2">
<asp:Label ID="EntryCode" runat="server" Text="1"></asp:Label>
</td>
<td class="auto-style19" colspan="6">
Current User
</td>
<td class="auto-style15" colspan="10">
<asp:Label ID="CurrentUser" runat="server" Text="CurrentUser"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style54">
Book Name
</td>
<td class="auto-style19" colspan="23">
<asp:TextBox ID="BookName" runat="server" Width="581px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style54">
Author
</td>
<td class="auto-style19" colspan="3">
<asp:TextBox ID="Author" runat="server" Width="204px"></asp:TextBox>
</td>
<td class="auto-style19" colspan="3">
Group
</td>
<td class="auto-style61" colspan="6">
<asp:DropDownList ID="Groupdata" runat="server" Height="18px" Width="179px">
<asp:ListItem>NONE</asp:ListItem>
<asp:ListItem>Olevel Book</asp:ListItem>
<asp:ListItem>ADVANCED LEVEL</asp:ListItem>
<asp:ListItem>PRIMARY</asp:ListItem>
</asp:DropDownList>
</td>
<td class="auto-style19" colspan="11">
</td>
</tr>
<tr>
<td class="auto-style54">
Subject
</td>
<td class="auto-style19" colspan="23">
<asp:DropDownList ID="SubjectData" runat="server" Height="26px" Width="584px">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="auto-style54">
Editions
</td>
<td class="auto-style19" colspan="3">
<asp:DropDownList ID="Editionsdata" runat="server" Height="22px" Width="238px">
</asp:DropDownList>
</td>
<td class="auto-style19" colspan="2">
Publisher
</td>
<td class="auto-style15" colspan="6">
<asp:TextBox ID="Publisher" runat="server" Width="141px"></asp:TextBox>
</td>
<td class="auto-style48" colspan="3">
Year Published
</td>
<td class="auto-style15" colspan="4">
<asp:TextBox ID="YearPublished" runat="server" Width="115px"></asp:TextBox>
</td>
<td class="auto-style15" colspan="5">
</td>
</tr>
<tr>
<td class="auto-style35">
ISBN
</td>
<td class="auto-style6" colspan="4">
<asp:TextBox ID="ISBN" runat="server" Width="219px"></asp:TextBox>
</td>
<td class="auto-style25" rowspan="2">
Notes
</td>
<td colspan="5" rowspan="2">
<asp:TextBox ID="Notes" runat="server" TextMode="MultiLine" Width="214px"></asp:TextBox>
</td>
<td colspan="5">
</td>
<td colspan="2">
</td>
<td colspan="4">
</td>
<td colspan="2">
</td>
</tr>
<tr>
<td class="auto-style36">
ISSN
</td>
<td class="auto-style37" colspan="4">
<asp:TextBox ID="ISSN" runat="server" Width="204px"></asp:TextBox>
</td>
<td colspan="7">
Preceding Zeros:
</td>
<td class="auto-style49" colspan="2">
<asp:CheckBox ID="CheckBox1" runat="server" />
</td>
<td colspan="2">
<asp:DropDownList ID="Nt" runat="server" CssClass="auto-style46" Height="23px" Width="56px">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
</asp:DropDownList>
</td>
<td>
</td>
<td>
<asp:TextBox ID="Code2" runat="server" Width="38px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style54">
Maximum
</td>
<td class="auto-style58">
<asp:TextBox ID="Minimum0" runat="server" Width="48px"></asp:TextBox>
</td>
<td class="auto-style60">
<asp:TextBox ID="Accs" runat="server" Visible="False" Width="31px"></asp:TextBox>
</td>
<td class="auto-style19">
<strong>Category</strong>
</td>
<td class="auto-style15" colspan="2">
<asp:DropDownList ID="DdlTypes" runat="server">
<asp:ListItem>BY SCHOOL</asp:ListItem>
<asp:ListItem>DONATED</asp:ListItem>
<asp:ListItem>NOT USED</asp:ListItem>
<asp:ListItem>WISHERS</asp:ListItem>
<asp:ListItem>NONE</asp:ListItem>
</asp:DropDownList>
</td>
<td class="auto-style19" colspan="2">
Qty
</td>
<td class="auto-style19">
<asp:TextBox ID="Qty" runat="server" Width="49px"></asp:TextBox>
</td>
<td class="auto-style19">
Start
</td>
<td class="auto-style19" colspan="4">
<asp:TextBox ID="start" runat="server" Width="123px"></asp:TextBox>
</td>
<td class="auto-style50" colspan="3">
CostPrice
</td>
<td class="auto-style57" colspan="2">
<asp:TextBox ID="CostPrice" runat="server" Width="78px"></asp:TextBox>
</td>
<td class="auto-style55" colspan="2">
Date
</td>
<td class="auto-style15" colspan="3">
<asp:TextBox ID="Dater" runat="server" Width="96px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style54">
</td>
<td class="auto-style15" colspan="23">
<asp:RadioButtonList ID="RadioButtonList2" runat="server" BorderColor="Blue" BorderStyle="Double"
RepeatDirection="Horizontal" Width="788px" AutoPostBack="True" OnSelectedIndexChanged="RadioButtonList2_SelectedIndexChanged">
<asp:ListItem>None</asp:ListItem>
<asp:ListItem>Back To Menu</asp:ListItem>
<asp:ListItem>Update Data</asp:ListItem>
<asp:ListItem>Post Books</asp:ListItem>
<asp:ListItem>Process Accessioning</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td class="auto-style5" colspan="24">
<asp:GridView ID="CateauditGrid" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="Groupcode" HeaderText="UserID" />
<asp:BoundField DataField="Bookcode" HeaderText="AccNumber" />
<asp:BoundField DataField="BookName" HeaderText="BookName" />
<asp:BoundField DataField="author" HeaderText="Author" />
<asp:BoundField DataField="Subject" HeaderText="Subject" />
<asp:BoundField DataField="Hold" HeaderText="Hold" />
<asp:BoundField DataField="bcode" HeaderText="bcode" />
<asp:BoundField DataField="Type" HeaderText="Type" />
<asp:BoundField DataField="CostPrice" HeaderText="CostPrice" />
<asp:BoundField DataField="Date" HeaderText="DateTime" />
<asp:BoundField DataField="Username" HeaderText="User Name" />
</Columns>
</asp:GridView>
</td>
</tr>
</table>
<asp:LinkButton ID="lnkDummy" runat="server"></asp:LinkButton>
<cc1:ModalPopupExtender ID="ModalPopupExtender1" BehaviorID="mpe" runat="server"
PopupControlID="pnlPopup" TargetControlID="lnkDummy" BackgroundCssClass="modalBackground"
CancelControlID="btnNo">
</cc1:ModalPopupExtender>
<asp:Panel ID="pnlPopup" runat="server" CssClass="modalPopup" Style="display: none">
<div class="header">
</div>
<div class="body">
<asp:Label ID="lblMessage" runat="server" Text="Do you want to save data?" />
<br />
</div>
<div class="footer">
<asp:Button ID="btnYes" runat="server" Text="Yes" OnClick="OnYes" />
<asp:Button ID="btnNo" runat="server" Text="No" />
</div>
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnYes" />
</Triggers>
</asp:UpdatePanel>
Namespaces
C#
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
VB.Net
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Code
C#
private string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
private string hold;
protected void Page_Load(object sender, System.EventArgs e)
{
if (!this.IsPostBack)
{
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT UserID, Subject FROM BookDetails"))
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
SubjectData.DataSource = cmd.ExecuteReader();
SubjectData.DataTextField = "Subject";
SubjectData.DataValueField = "UserID";
SubjectData.DataBind();
con.Close();
}
}
SubjectData.Items.Insert(0, new ListItem("--Select Subject--", "0"));
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT UserID,CostPrice FROM BookDetails"))
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
Editionsdata.DataSource = cmd.ExecuteReader();
Editionsdata.DataTextField = "CostPrice";
Editionsdata.DataValueField = "UserID";
Editionsdata.DataBind();
con.Close();
}
}
Editionsdata.Items.Insert(0, new ListItem("--Select Editions--", "0"));
}
if (Session["Hold"] != null)
{
hold = "Update";
}
else
{
using (SqlConnection Con = new SqlConnection(constr))
{
Con.Open();
using (SqlCommand Com = new SqlCommand("Select bcode from BookDetails", Con))
{
using (var RDR = Com.ExecuteReader())
{
if (RDR.HasRows)
{
RDR.Read();
}
}
}
Con.Close();
}
if (Code2.Text != "")
start.Text = Code2.Text;
else
{
start.Text = Accs.Text;
start.ReadOnly = false;
}
}
}
protected void RadioButtonList2_SelectedIndexChanged(object sender, EventArgs e)
{
if (RadioButtonList2.SelectedItem.Text == "Back To Menu")
{
Response.Redirect("~/Forms/Subcodes.aspx");
}
else if (RadioButtonList2.SelectedItem.Text == "Update Data")
{
ModalPopupExtender1.Show();
}
else if (RadioButtonList2.SelectedItem.Text == "Reporting")
Response.Redirect("~/Reports/Treereport.aspx");
else if (RadioButtonList2.SelectedItem.Text == "Register Services")
Response.Redirect("~/Forms/Servicesdata.aspx");
}
protected void OnYes(object sender, EventArgs e)
{
using (SqlConnection Conb = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("select * from BookDetails"))
{
cmd.Connection = Conb;
cmd.Parameters.Add("@UserID", SqlDbType.Int).Value = Convert.ToInt32(EntryCode.Text);
cmd.Parameters.Add("@AccNumber", SqlDbType.VarChar).Value = BookName.Text;
cmd.Parameters.Add("@BookName", SqlDbType.VarChar).Value = Callno.Text;
cmd.Parameters.Add("@Author", SqlDbType.VarChar).Value = Author.Text;
cmd.Parameters.Add("@Subject", SqlDbType.VarChar).Value = SubjectData.SelectedItem.Text;
// cmd.Parameters.AddWithValue("@subj", row.Cells(i).Controls.OfType(Of DropDownList)().FirstOrDefault().SelectedItem.Value)
cmd.Parameters.Add("@Type", SqlDbType.VarChar).Value = Publisher.Text;
cmd.Parameters.Add("@CostPrice", SqlDbType.VarChar).Value = YearPublished.Text;
cmd.Parameters.Add("@DateTime", SqlDbType.VarChar).Value = ISBN.Text;
cmd.Parameters.Add("@Username", SqlDbType.VarChar).Value = Editionsdata.SelectedItem.Text;
Conb.Open();
cmd.ExecuteNonQuery();
Conb.Close();
}
}
ScriptManager.RegisterStartupScript(this, this.GetType(), "showalert", "alert('Book Details Updated to the Database Successfully');", true);
}
VB.Net
Private constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Private hold As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Using con As SqlConnection = New SqlConnection(constr)
Using cmd As SqlCommand = New SqlCommand("SELECT UserID, Subject FROM BookDetails")
cmd.CommandType = CommandType.Text
cmd.Connection = con
con.Open()
SubjectData.DataSource = cmd.ExecuteReader()
SubjectData.DataTextField = "Subject"
SubjectData.DataValueField = "UserID"
SubjectData.DataBind()
con.Close()
End Using
End Using
SubjectData.Items.Insert(0, New ListItem("--Select Subject--", "0"))
Using con As SqlConnection = New SqlConnection(constr)
Using cmd As SqlCommand = New SqlCommand("SELECT UserID,CostPrice FROM BookDetails")
cmd.CommandType = CommandType.Text
cmd.Connection = con
con.Open()
Editionsdata.DataSource = cmd.ExecuteReader()
Editionsdata.DataTextField = "CostPrice"
Editionsdata.DataValueField = "UserID"
Editionsdata.DataBind()
con.Close()
End Using
End Using
Editionsdata.Items.Insert(0, New ListItem("--Select Editions--", "0"))
End If
If Session("Hold") IsNot Nothing Then
hold = "Update"
Else
Using Con As SqlConnection = New SqlConnection(constr)
Con.Open()
Using Com As SqlCommand = New SqlCommand("Select bcode from BookDetails", Con)
Using RDR = Com.ExecuteReader()
If RDR.HasRows Then
RDR.Read()
End If
End Using
End Using
Con.Close()
End Using
If Code2.Text <> "" Then
start.Text = Code2.Text
Else
start.Text = Accs.Text
start.[ReadOnly] = False
End If
End If
End Sub
Protected Sub RadioButtonList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
If RadioButtonList2.SelectedItem.Text = "Back To Menu" Then
Response.Redirect("~/Forms/Subcodes.aspx")
ElseIf RadioButtonList2.SelectedItem.Text = "Update Data" Then
ModalPopupExtender1.Show()
ElseIf RadioButtonList2.SelectedItem.Text = "Reporting" Then
Response.Redirect("~/Reports/Treereport.aspx")
ElseIf RadioButtonList2.SelectedItem.Text = "Register Services" Then
Response.Redirect("~/Forms/Servicesdata.aspx")
End If
End Sub
Protected Sub OnYes(ByVal sender As Object, ByVal e As EventArgs)
Using Conb As SqlConnection = New SqlConnection(constr)
Using cmd As SqlCommand = New SqlCommand("select * from BookDetails")
cmd.Connection = Conb
cmd.Parameters.Add("@UserID", SqlDbType.Int).Value = Convert.ToInt32(EntryCode.Text)
cmd.Parameters.Add("@AccNumber", SqlDbType.VarChar).Value = BookName.Text
cmd.Parameters.Add("@BookName", SqlDbType.VarChar).Value = Callno.Text
cmd.Parameters.Add("@Author", SqlDbType.VarChar).Value = Author.Text
cmd.Parameters.Add("@Subject", SqlDbType.VarChar).Value = SubjectData.SelectedItem.Text
cmd.Parameters.Add("@Type", SqlDbType.VarChar).Value = Publisher.Text
cmd.Parameters.Add("@CostPrice", SqlDbType.VarChar).Value = YearPublished.Text
cmd.Parameters.Add("@DateTime", SqlDbType.VarChar).Value = ISBN.Text
cmd.Parameters.Add("@Username", SqlDbType.VarChar).Value = Editionsdata.SelectedItem.Text
Conb.Open()
cmd.ExecuteNonQuery()
Conb.Close()
End Using
End Using
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "showalert", "alert('Book Details Updated to the Database Successfully');", True)
End Sub
Screenshot