I have few textboxes on one page and one user control. What I want is when user click in particular or when textbox gain a focus, it should open pop up. The user control contains a grid which is filled in load event. Now when user clicks on a button, the popup should get closed and textboxes the patent page should get filled with the values from the selected row.
How to do this?
Here is the code for my .aspx page and use control page.
Code for Parent page
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<table class="style1" width="100%">
<tr>
<td width="20%">
ID</td>
<td width="60%">
<asp:TextBox ID="txtID" runat="server" ontextchanged="txtID_TextChanged"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td>
Name</td>
<td>
<asp:TextBox ID="txtName" runat="server" ontextchanged="txtName_TextChanged"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td>
HOD</td>
<td>
<asp:TextBox ID="txtHOD" runat="server"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td>
Email</td>
<td>
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnGet" runat="server" onclick="btnGet_Click"
Text="Get Values" />
</td>
<td>
</td>
</tr>
</table>
</div>
<UC:UserControl ID="UC1" runat="server" />
</form>
Parent page .aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if(Session["dtTable"] != null)
{
Hashtable Table = (Hashtable)Session["dtTable"];
txtID.Text = Table["ID"].ToString();
txtHOD.Text = Table["HOD"].ToString();
txtName.Text = Table["Name"].ToString();
txtEmail.Text = Table["Email"].ToString();
}
}
protected void txtID_TextChanged(object sender, EventArgs e)
{
UC1.Show();
Page.Controls.Add(UC1);
}
Code for User control .ascx page
<ContentTemplate>
<asp:Panel ID="DisplayPanel" runat="server">
<table class="style1">
<tr>
<td width="25%">
</td>
<td align="right">
</td>
<td width="25%">
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" GridLines="None"
onrowcommand="GridView1_RowCommand">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="DeptId" HeaderText="ID"/>
<asp:BoundField DataField="Name" HeaderText="Name"/>
<asp:BoundField DataField="HeadName" HeaderText="HOD"/>
<asp:BoundField DataField="HeadEmail" HeaderText="Email"/>
<asp:TemplateField>
<HeaderTemplate>
Select
</HeaderTemplate>
<ItemTemplate>
<asp:Button ID="btnAdd" runat="server" Text="ADD" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
</td>
<td>
</td>
</tr>
</table>
Code for user control .ascx.cs page
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection oConnection = new SqlConnection("Data Source=websrv3;Initial Catalog=20110801_AcrosBackup;Persist Security Info=True;User ID=sa;Password=SQL#admin");
SqlCommand oCommand = new SqlCommand("select * from Department", oConnection);
SqlDataAdapter oAdapter = new SqlDataAdapter(oCommand);
DataTable dt = new DataTable();
oAdapter.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
Hashtable dtTable = new Hashtable();
int intRowInd = ((GridViewRow)(((Button)e.CommandSource).NamingContainer)).RowIndex;
dtTable.Add("ID",GridView1.Rows[intRowInd].Cells[0].Text);
dtTable.Add("Name", GridView1.Rows[intRowInd].Cells[1].Text);
dtTable.Add("HOD", GridView1.Rows[intRowInd].Cells[2].Text);
dtTable.Add("Email", GridView1.Rows[intRowInd].Cells[3].Text);
Session.Add("dtTable", dtTable);
}
public void Show()
{
this.ModalPopupExtender1.Show();
}
</asp:Panel>
<asp:Button ID="fake" runat="server" Style="display:none" />
<cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="fake" PopupControlID="DisplayPanel" BackgroundCssClass="overlay_style">
</cc1:ModalPopupExtender>
</ContentTemplate>
Add this onfocus attribute to your textbox.
onfocus="$find("<%= YourModalPopupExtenderID.ClientID %>").show();"
Related
I'm developing an Asp.net web site.
I'm using Ajax:ModalPopupExtender for displaying some information.
Html
<asp:UpdatePanel ID="upnlModelPopup" runat="server" UpdateMode="Conditional">
<ContentTemplate>
Form control goes here...............
<asp:Button ID="btnShow" runat="server" CssClass="btn" Text="Adjustment" OnClick="btnShow_Click" Enabled="true" />
<cc1:ModalPopupExtender ID="mpeAdjAmt" runat="server" TargetControlID="lblHead"
PopupControlID="pnlMsg" BackgroundCssClass="displayHide"
DropShadow="true" OkControlID="lblStsFoot" OnOkScript="setFocus()" >
</cc1:ModalPopupExtender>
<asp:Panel ID="pnlMsg" runat="server" CssClass="ErrorPanel" >
<table width="100%">
<tr>
<td >
<asp:Label ID="lblHead" CssClass="lblHead" runat="server"
Text=""></asp:Label>
</td>
</tr>
<tr>
<td >
<table class="tblTableHead" >
<tr >
<td style ="width:4%;">S.No</td>
<td style ="width:21%;">Type</td>
<td style ="width:25%;">Date</td>
<td style ="width:20%;">Amount Type</td>
<td style ="width:15%;">Amount</td>
<td style ="width:15%;">Adjust Amount</td>
</tr>
</table>
<div id="divGridStatus" style="width:100%;max-height:300px;overflow-Y:auto;overflow-X:hidden;" >
<asp:GridView ID="grvStatus" runat="server" Width="100%"
AutoGenerateColumns="false" CssClass="GridViewStyle" GridLines="None" ShowHeader="false" >
<Columns>
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="lnkSNo" runat="server" CssClass="lbl"
Width="100%" OnClientClick="return false;" Font-Underline="false"
ReadOnly="true" >
<%# ((GridViewRow)Container).RowIndex + 1%>
</asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="4%" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="lnkwsid" runat="server" Width="100%" OnClientClick="return false;"
ReadOnly="true" Font-Underline="false"
Text='<%# Bind("wsid") %>' >
</asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="21%" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="lnknm" runat="server" Width="100%" OnClientClick="return false;"
ReadOnly="true" Font-Underline="false"
Text='<%# Bind("nm") %>' >
</asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="25%" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="lnkgrp1" runat="server" Width="100%" OnClientClick="return false;"
ReadOnly="true" Font-Underline="false" Text='<%# Bind("grp1") %>' >
</asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="20%" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="lnkoptid" runat="Server" CssClass="lbl"
Width="100%" OnClientClick="return false;" Font-Underline="false"
ReadOnly="true" Text='<%# Bind("optid") %>' >
</asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="15%" />
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="lnkuid" runat="server"
Width="100%" CssClass="lbl" OnClientClick="return false;" Font-Underline="false"
ReadOnly="true" Text='<%# Bind("uid") %>' >
</asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="15%" />
</asp:TemplateField>
</Columns>
<FooterStyle CssClass="FooterStyle" />
<RowStyle CssClass="RowStyle" />
<EmptyDataRowStyle CssClass="EmptyRowStyle" />
<EmptyDataTemplate>
No Data Found.
</EmptyDataTemplate>
<PagerStyle CssClass="PagerStyle" />
<SelectedRowStyle CssClass="SelectedRowStyle" />
<HeaderStyle CssClass="HeaderStyle" />
<EditRowStyle CssClass="EditRowStyle" />
<AlternatingRowStyle CssClass="AltRowStyle" />
</asp:GridView>
</div>
<table class="tblTableHead" style="padding-left:1%;">
<tr>
<td>
<asp:Label ID="lblStsFoot" runat="server" Text="" ></asp:Label>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<br />
<%--OnClientClick="return CheckAdjustment();"OnClientClick="ShowWait();"--%>
<asp:Button ID="btnAdjust" runat="server" Text="Done" CssClass="btn" OnClick="btnAdjust_Click"
buttonAction="submitButton" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" CssClass="btn" OnClick="btnCancel_Click"
buttonAction="submitButton" />
</td>
</tr>
</table>
<br />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
C# Code
protected void btnShow_Click(object sender, EventArgs e)
{
mpeAdjAmt.Show();
upnlModelPopup.Update();
}
protected void btnAdjust_Click(object sender, EventArgs e)
{
//Code goes here...
mpeAdjAmt.Hide();
upnlModelPopup.Update();
}
protected void btnCancel_Click(object sender, EventArgs e)
{
mpeAdjAmt.Hide();
upnlModelPopup.Update();
}
I'm showing/hiding this panel from code behind.
When i click's on show button first time it works very fine it shows panel proper.
My problem is when i click's on show button second time it doesn't show panel.
If i removed update panel it works fine when we use to show and hide panel from code behind but it starts flicker of panel on page load and works fine .
Can any one tell me what is the problem and how can i solve that.
Try doing
protected void btnShow_Click(object sender, EventArgs e)
{
mpeAdjAmt.Show();
upnlModelPopup.Update();
mpeAdjAmt.BackgroundCssClass="displayHide";
//or
//pnlMsg.CssClass="ErrorPanel";
}
protected void btnAdjust_Click(object sender, EventArgs e)
{
//Code goes here...
mpeAdjAmt.Hide();
upnlModelPopup.Update();
mpeAdjAmt.BackgroundCssClass="displayHide";
//or
//pnlMsg.CssClass="ErrorPanel";
}
protected void btnCancel_Click(object sender, EventArgs e)
{
mpeAdjAmt.Hide();
upnlModelPopup.Update();
mpeAdjAmt.BackgroundCssClass="displayHide";
//or
//pnlMsg.CssClass="ErrorPanel";
}
I have a Button with id=btnSend that named "Send" in GridView.
I have a ModalPopUpExtender id="SendPopUp" and TargetControlID="btnSend"
and
<asp:Panel id="SendPanel">
I get the error as
System.InvalidOperationException: The TargetControlID of '
SendPopUp'is not valid. A control with ID 'btnSend' could not be
found.
How do I make it work?
You need to add the Click event of button then from code behind file you can show model popup by simply write code in button click event
modal.show()
For your reference i am providing you complete code as follow.
I hope it will help you.
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.modalBackground
{
background-color: Gray;
filter: alpha(opacity=80);
opacity: 0.8;
z-index: 10000;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<div>
<asp:GridView runat="server" ID="gvdetails" DataKeyNames="UserId" AutoGenerateColumns="false">
<RowStyle BackColor="#EFF3FB" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:ImageButton ID="imgbtn" ImageUrl="~/Edit.jpg" runat="server" Width="25" Height="25" onclick="imgbtn_Click" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UserName" HeaderText="UserName" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:BoundField DataField="City" HeaderText="City" />
<asp:BoundField DataField="Designation" HeaderText="Designation" />
</Columns>
</asp:GridView>
<asp:Label ID="lblresult" runat="server"/>
<asp:Button ID="btnShowPopup" runat="server" style="display:none" />
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnShowPopup" PopupControlID="pnlpopup"
CancelControlID="btnCancel" BackgroundCssClass="modalBackground">
</asp:ModalPopupExtender>
<asp:Panel ID="pnlpopup" runat="server" BackColor="White" Height="269px" Width="400px" style="display:none">
<table width="100%" style="border:Solid 3px #D55500; width:100%; height:100%" cellpadding="0" cellspacing="0">
<tr style="background-color:#D55500">
<td colspan="2" style=" height:10%; color:White; font-weight:bold; font-size:larger" align="center">User Details</td>
</tr>
<tr>
<td align="right" style=" width:45%">
UserId:
</td>
<td>
<asp:Label ID="lblID" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td align="right">
UserName:
</td>
<td>
<asp:Label ID="lblusername" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td align="right">
FirstName:
</td>
<td>
<asp:TextBox ID="txtfname" runat="server"/>
</td>
</tr>
<tr>
<td align="right">
LastName:
</td>
<td>
<asp:TextBox ID="txtlname" runat="server"/>
</td>
</tr>
<tr>
<td align="right">
City:
</td>
<td>
<asp:TextBox ID="txtCity" runat="server"/>
</td>
</tr>
<tr>
<td align="right">
Designation:
</td>
<td>
<asp:TextBox ID="txtDesg" runat="server"/>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnUpdate" CommandName="Update" runat="server" Text="Update" onclick="btnUpdate_Click"/>
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
</td>
</tr>
</table>
</asp:Panel>
</div>
</form>
</body>
</html>
Code Behind file
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ToString());
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
BindGridData();
}
}
protected void BindGridData()
{
con.Open();
SqlCommand cmd = new SqlCommand("Select * from Employee_Details", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
gvdetails.DataSource = dt;
gvdetails.DataBind();
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("update Employee_Details set FirstName=#FirstName,LastName=#LastName, City=#City,Designation=#Designation where UserId=#UserId", con);
cmd.Parameters.AddWithValue("#FirstName", txtfname.Text);
cmd.Parameters.AddWithValue("#LastName", txtlname.Text);
cmd.Parameters.AddWithValue("#City", txtCity.Text);
cmd.Parameters.AddWithValue("#Designation", txtDesg.Text);
cmd.Parameters.AddWithValue("#UserId", Convert.ToInt32(lblID.Text));
cmd.ExecuteNonQuery();
con.Close();
lblresult.Text = lblusername.Text + " Details Updated Successfully";
lblresult.ForeColor = Color.Green;
BindGridData();
}
protected void imgbtn_Click(object sender, ImageClickEventArgs e)
{
ImageButton btndetails = sender as ImageButton;
GridViewRow gvrow = (GridViewRow)btndetails.NamingContainer;
lblID.Text = gvdetails.DataKeys[gvrow.RowIndex].Value.ToString();
lblusername.Text = gvrow.Cells[1].Text;
txtfname.Text = gvrow.Cells[2].Text;
txtlname.Text = gvrow.Cells[3].Text;
txtCity.Text = gvrow.Cells[4].Text;
txtDesg.Text = gvrow.Cells[5].Text;
this.ModalPopupExtender1.Show();
}
since your panel if outside of the gridview it wont work this way. add a hiddenfield and set the targetcontrolid to that field. Next in the button click of the gridview use modalpopup.show();
I guys i have two page On fist page i have my form and on second is report page where my form values store in grid. i have submit button on my form page now when i click on edit link i will redirect to my form page where i can make change and update details. now what i want is when i click on edit link and move to my form page to make editing my submit button change to update button how can i do that...
here is my code for first page:
Select
TRAVELONG
ONETRAVEL
.UK-BSP
.CA-YYZ
.CA-YVR
Partial MCO Refund
<div id="FirstForm" style="margin-left: 80px" runat="server">
<table class="style1">
<tr>
<td class="style13">
<asp:Label ID="lblTid" runat="server" Text="TID"></asp:Label>
</td>
<td class="style5">
<asp:TextBox ID="tbTid" runat="server"></asp:TextBox>
</td>
<td class="style4">
<asp:RequiredFieldValidator ID="rfvTid" runat="server"
ControlToValidate="tbTid" ErrorMessage="Enter Tid" Font-Bold="True"
ForeColor="Red">*</asp:RequiredFieldValidator>
</td>
<td class="style5">
<asp:Label ID="lblUnusedTicketAmount" runat="server"
Text="Unused Ticket Amount"></asp:Label>
</td>
<td class="style11">
<asp:TextBox ID="tbUnusedTicketAmount" runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvUnusedTicketAmount" runat="server"
ControlToValidate="tbUnusedTicketAmount" ErrorMessage="Enter Amount"
Font-Bold="True" ForeColor="Red">*</asp:RequiredFieldValidator>
</td>
<td>
<asp:DropDownList ID="ddlUnusedAmount" runat="server">
<asp:ListItem>USD</asp:ListItem>
<asp:ListItem>CAD</asp:ListItem>
<asp:ListItem>GBP</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style14">
<asp:Label ID="lblPNR" runat="server" Text="PNR"></asp:Label>
</td>
<td class="style9">
<asp:TextBox ID="tbPNR" runat="server"></asp:TextBox>
</td>
<td class="style8">
<asp:RequiredFieldValidator ID="rfvPNR" runat="server"
ControlToValidate="tbPNR" ErrorMessage="Enter PNR" Font-Bold="True"
ForeColor="Red">*</asp:RequiredFieldValidator>
</td>
<td class="style9">
<asp:Label ID="lblAirlinePenality" runat="server" Text="Airline Penality"></asp:Label>
</td>
<td class="style12">
<asp:TextBox ID="tbAirlinePenality" runat="server"></asp:TextBox>
</td>
<td class="style10">
<asp:RequiredFieldValidator ID="rfvAirlinePenality" runat="server"
ControlToValidate="tbAirlinePenality" ErrorMessage="Enter Penality"
Font-Bold="True" ForeColor="Red">*</asp:RequiredFieldValidator>
</td>
<td class="style10">
<asp:DropDownList ID="ddlAirlinePenality" runat="server" AutoPostBack="True">
<asp:ListItem>USD</asp:ListItem>
<asp:ListItem>CAD</asp:ListItem>
<asp:ListItem>GBP</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style13">
<asp:Label ID="lblTicketNumber" runat="server" Text="Ticket Number"></asp:Label>
</td>
<td class="style5">
<asp:TextBox ID="tbTicketNumber" runat="server"></asp:TextBox>
</td>
<td class="style4">
<asp:RequiredFieldValidator ID="rfvTicketNumber" runat="server"
ControlToValidate="tbTicketNumber" ErrorMessage="Enter ESAC" Font-Bold="True"
ForeColor="Red">*</asp:RequiredFieldValidator>
</td>
<td class="style5">
<asp:Label ID="lblNetRefundProcess" runat="server" Text="Net Refund Process"></asp:Label>
</td>
<td class="style11">
<asp:TextBox ID="tbNetRefundProcess" runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvNetRefundProcess" runat="server"
ControlToValidate="tbNetRefundProcess" ErrorMessage="RequiredFieldValidator"
Font-Bold="True" ForeColor="Red">*</asp:RequiredFieldValidator>
</td>
<td>
<asp:DropDownList ID="ddlNetRefundProcess" runat="server" AutoPostBack="True">
<asp:ListItem>USD</asp:ListItem>
<asp:ListItem>CAD</asp:ListItem>
<asp:ListItem>GBP</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style13">
<asp:Label ID="lblESACCode" runat="server" Text="ESAC Code"></asp:Label>
</td>
<td class="style5">
<asp:TextBox ID="tbESACCode" runat="server"></asp:TextBox>
</td>
<td class="style4">
<asp:RequiredFieldValidator ID="rfvESACCode" runat="server"
ControlToValidate="tbESACCode" ErrorMessage="Enter ESAC code" Font-Bold="True"
ForeColor="Red">*</asp:RequiredFieldValidator>
</td>
<td class="style5">
<asp:Label ID="lblRefundableCommision" runat="server"
Text="Refundable Commission"></asp:Label>
</td>
<td class="style11">
<asp:TextBox ID="tbRefundableCommision" runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvRefundableCommission" runat="server"
ControlToValidate="tbRefundableCommision" ErrorMessage="RequiredFieldValidator"
Font-Bold="True" ForeColor="Red">*</asp:RequiredFieldValidator>
</td>
<td>
<asp:DropDownList ID="ddlRefundableCommission" runat="server"
AutoPostBack="True">
<asp:ListItem>USD</asp:ListItem>
<asp:ListItem>CAD</asp:ListItem>
<asp:ListItem>GBP</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style13">
<asp:Label ID="lblWaiverCode" runat="server" Text="Waiver Code"></asp:Label>
</td>
<td class="style5">
<asp:TextBox ID="tbWaiverCode" runat="server"></asp:TextBox>
</td>
<td class="style4">
<asp:RequiredFieldValidator ID="rfvWaiverCode" runat="server"
ControlToValidate="tbWaiverCode" ErrorMessage="Enter Waiver Code"
Font-Bold="True" ForeColor="Red">*</asp:RequiredFieldValidator>
</td>
<td class="style5">
<asp:Label ID="lblCouponRefunded" runat="server" Text="Coupon Refunded"></asp:Label>
</td>
<td class="style11">
<asp:TextBox ID="tbCouponRefund" runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvCouponRefunded" runat="server"
ControlToValidate="tbCouponRefund" ErrorMessage="Enter Coupon Refund"
Font-Bold="True" ForeColor="Red">*</asp:RequiredFieldValidator>
</td>
<td>
</td>
</tr>
<tr>
<td class="style13">
<asp:Label ID="Label7" runat="server" Text="Remarks"></asp:Label>
</td>
<td class="style5">
<asp:TextBox ID="tbRemarks" runat="server" TextMode="MultiLine"></asp:TextBox>
</td>
<td class="style4">
<asp:RequiredFieldValidator ID="rfvRemarks" runat="server"
ControlToValidate="tbRemarks" ErrorMessage="Enter Remarks" Font-Bold="True"
ForeColor="Red">*</asp:RequiredFieldValidator>
</td>
<td class="style5">
<asp:Label ID="lblRefundType" runat="server" Text="Refund Type"></asp:Label>
</td>
<td class="style11">
<asp:DropDownList ID="ddlRefundType" runat="server">
<asp:ListItem>Full</asp:ListItem>
<asp:ListItem>Partial</asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvRefundType" runat="server"
ControlToValidate="ddlRefundType" ErrorMessage="Select Refund Type"
Font-Bold="True" ForeColor="Red">*</asp:RequiredFieldValidator>
</td>
<td>
</td>
</tr>
<tr>
<td class="style13" colspan="7">
<asp:Button ID="btnSubmit" runat="server" onclick="btnSubmit_Click" Text="Submit"/>
<asp:Button ID="btnReset" runat="server" onclick="btnReset_Click" Text="Reset"/>
</td>
</tr>
</table>
aspx.cs page code:
protected void btnSubmit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=Bart;Integrated Security=True");
con.Open();
string Portal = ddlPortal.SelectedValue;
string TID = tbTid.Text;
string PNR = tbPNR.Text;
string TicketNumber = tbTicketNumber.Text;
string ESACCode = tbESACCode.Text;
string WaiverCode = tbWaiverCode.Text;
string Remarks = tbRemarks.Text;
string UnusedTicketAmount = tbUnusedTicketAmount.Text;
string UnusedAmount = ddlUnusedAmount.SelectedValue;
string AirlinePenality = tbAirlinePenality.Text;
string Airline = ddlAirlinePenality.SelectedValue;
string NetRefundProcess = tbNetRefundProcess.Text;
string NetRefund = ddlNetRefundProcess.SelectedValue;
string RefundableCommission = tbRefundableCommision.Text;
string Refundable = ddlRefundableCommission.SelectedValue;
string CouponRefunded = tbCouponRefund.Text;
string RefundType = ddlRefundType.SelectedValue;
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = "insert into Form3(Portal,TID,PNR,TicketNumber,ESACCode,WaiverCode,Remarks,UnusedTicketAmount,ddlUnusedAmount, AirlinePenality, ddlAirlinePenality, NetRefundProcess, ddlNetRefundProcess, RefundableCommission, ddlRefundableCommission, CouponRefunded,RefundType) values('" + Portal + "','" + TID + "','" + PNR + "','" + TicketNumber + "', '" + ESACCode + "', '" + WaiverCode + "', '" + Remarks + "','" + UnusedTicketAmount + "','" + UnusedAmount + "','" + AirlinePenality + "','" + Airline + "','" + NetRefundProcess + "','" + NetRefund + "','" + RefundableCommission + "','" + Refundable + "','" + CouponRefunded + "','" + RefundType + "')";
cmd.Parameters.AddWithValue("#Portal", ddlPortal.SelectedIndex);
cmd.Parameters.AddWithValue("#TID", tbTid.Text.Trim());
cmd.Parameters.AddWithValue("#PNR", tbPNR.Text.Trim());
cmd.Parameters.AddWithValue("#TicketNumber", tbTicketNumber.Text.Trim());
cmd.Parameters.AddWithValue("#ESACCode", tbESACCode.Text.Trim());
cmd.Parameters.AddWithValue("#WaiverCode", tbWaiverCode.Text.Trim());
cmd.Parameters.AddWithValue("#Remarks", tbRemarks.Text.Trim());
cmd.Parameters.AddWithValue("#UnusedTicketAmount", tbUnusedTicketAmount.Text.Trim());
cmd.Parameters.AddWithValue("#ddlUnusedAmount", ddlUnusedAmount.SelectedIndex);
cmd.Parameters.AddWithValue("#AirlinePenality", tbAirlinePenality.Text.Trim());
cmd.Parameters.AddWithValue("#ddlAirlinePenality", ddlAirlinePenality.SelectedIndex);
cmd.Parameters.AddWithValue("#NetRefundProcess", tbNetRefundProcess.Text.Trim());
cmd.Parameters.AddWithValue("#ddlNetRefundProcess", ddlNetRefundProcess.SelectedIndex);
cmd.Parameters.AddWithValue("#RefundableCommission", tbRefundableCommision.Text.Trim());
cmd.Parameters.AddWithValue("#ddlRefundableCommission", ddlRefundableCommission.SelectedIndex);
cmd.Parameters.AddWithValue("#CouponRefunded", tbCouponRefund.Text.Trim());
cmd.Parameters.AddWithValue("#RefundType", ddlRefundType.SelectedIndex);
cmd.ExecuteNonQuery();
}
con.Close();
tbTid.Text = "";
tbPNR.Text = "";
tbTicketNumber.Text = "";
tbESACCode.Text = "";
tbWaiverCode.Text = "";
tbRemarks.Text = "";
tbRemarks.Text = "";
tbUnusedTicketAmount.Text = "";
tbAirlinePenality.Text = "";
tbNetRefundProcess.Text = "";
tbRefundableCommision.Text = "";
tbCouponRefund.Text = "";
lblRefundType.Text = "";
tbTid.Focus();
}
Second report page::
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="None" AutoGenerateColumns="False"
onrowcommand="GridView1_RowCommand1">
<Columns>
<asp:TemplateField HeaderText="Query">
<itemtemplate>
<asp:LinkButton CommandName="cmdBind" runat="server" Text='<%#Eval("ID")%>' ID="ID" ToolTip='<%#Eval("ID")%>'>LinkButton
</asp:LinkButton>
</itemtemplate>
</asp:TemplateField>
<asp:BoundField DataField="Portal" HeaderText="Portal" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="TID" HeaderText="TID" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="PNR" HeaderText="PNR" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="TicketNumber" HeaderText="Ticket Number" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="ESACCode" HeaderText="ESACCode" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="WaiverCode" HeaderText="WaiverCode" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="Remarks" HeaderText="Remarks" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="UnusedTicketAmount" HeaderText="UnusedTicketAmount" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="ddlUnusedAmount" HeaderText="ddlUnusedAmoun" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="AirlinePenality" HeaderText="AirlinePenality" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="ddlAirlinePenality" HeaderText="ddlAirlinePenality" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="NetRefundProcess" HeaderText="NetRefundProcess" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="ddlNetRefundProcess" HeaderText="ddlNetRefundProcess" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="RefundableCommission" HeaderText="RefundableCommission" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="ddlRefundableCommission" HeaderText="ddlRefundableCommission" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="CouponRefunded" HeaderText="CouponRefunded" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="RefundType" HeaderText="RefundType" ItemStyle-HorizontalAlign="Center"/>
</Columns>
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
aspx.cs page of report:
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!Page.IsPostBack)
{
cmd = new SqlCommand("select * from Form3", con);
da = new SqlDataAdapter(cmd);
dt.Clear();
con.Open();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
con.Close();
}
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
protected void GridView1_RowCommand1(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "cmdBind")
{
LinkButton lb = (LinkButton)e.CommandSource;
Response.Redirect("Form.aspx?ID=" + lb.Text + "");
}
}
You need to use a State Management technique to implement this. I have used Session to demonstrate.
On your page where you have the Submit button you need to create a property like this:
public string ButtonTextValue
{
get
{
if (Session["ButtonValue"] == null)
Session["ButtonValue"] = "Submit";
return Convert.ToString(Session["ButtonValue"]);
}
set
{
Session["ButtonValue"] = value;
}
}
On pageload of the same page you need to do this:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
YourButton.Text = ButtonTextValue;
}
}
And on the second page you need to do this:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "cmdBind")
{
LinkButton lb = (LinkButton)e.CommandSource;
Session["ButtonValue"] = "Update";
Response.Redirect("Form.aspx?ID=" + lb.Text + "");
}
}
Getting the selected value on clicking button twice. But not working when click once
<asp:GridView ID="viewgrid" runat="server" AutoGenerateColumns="False"
OnRowCommand="viewgrid_RowCommand" OnRowDataBound="viewgrid_RowDataBound"
DataKeyNames="RegionID" >
<AlternatingRowStyle BackColor="#DCDCDC" />
<Columns>
<asp:TemplateField HeaderText="RegionName">
<HeaderStyle BackColor="#4B6C9E" ForeColor="White" />
<ItemTemplate>
<table style="width: 200px">
<tr>
<td>
<asp:Label ID="lblregion" runat="server"
Text='<%# Eval("name") %>' ToolTip='<%# Eval("RegionID") %>'>
</asp:Label><br />
</td>
</tr>
<tr>
<td>
<asp:ListBox ID="listlocation" runat="server" Width="200px"
Height="38px" SelectionMode="Multiple"
AppendDataBoundItems="true"></asp:ListBox>
</td>
</tr>
</table>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
<FooterStyle BackColor="#4B6C9E" ForeColor="White" Height="15px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Action">
<HeaderStyle BackColor="#4B6C9E" ForeColor="White" />
<ItemTemplate>
<table style="margin-top: 5px">
<tr>
<td>
<asp:Button ID="btnright" runat="server" CommandName="moveright" Text=">" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnallright" runat="server" CommandName="moveallright" Text=">>" />
</td>
</tr>
</table>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
<FooterStyle BackColor="#4B6C9E" ForeColor="White" />
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void viewgrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridView grd = (GridView)sender;
if (e.CommandName == "moveright")
{
//string newRegionID = string.Empty;
GridViewRow gridrow = (GridViewRow)((Button)e.CommandSource).NamingContainer;
int index = gridrow.RowIndex;
//ListBox region = (ListBox)(gridrow.FindControl("listlocation"));
ListBox region = (ListBox)(viewgrid.Rows[index].FindControl("listlocation"));
List<ListItem> selectedregions = new List<ListItem>();
List<object> toRemove = new List<object>();
foreach (ListItem li in region.Items)
{
if (li.Selected)
{
selectedregions.Add(li);
listlocation2.Items.Add(li);
}
}
foreach (ListItem lll in selectedregions)
{
region.Items.Remove(lll);
}
}
if (e.CommandName == "moveallright")
{
lblmessage.Visible = false;
GridViewRow gridrow = (GridViewRow)((Button)e.CommandSource).NamingContainer;
int index = gridrow.RowIndex;
ListBox locationlist1 = (ListBox)(viewgrid.Rows[index].FindControl("listlocation"));
while (locationlist1.Items.Count != 0)
{
for (int i = 0; i < locationlist1.Items.Count; i++)
{
listlocation2.Items.Add(locationlist1.Items[i]);
locationlist1.Items.Remove(locationlist1.Items[i]);
}
}
}
}
I want to add booth detail into database, after user insert booth alias, select booth type and booth duration, next click submit button and the newly added record will appear in the gridview below the old records.
I know there are something missing in the code but I not sure what is the problem.
The client code:
<%# Page Language="VB" MasterPageFile="~/MasterPageAdmin.master" AutoEventWireup="false" CodeFile="addbooth.aspx.vb" Inherits="addbooth" title="Untitled Page" %>
<%# Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="ContentPlaceHolder2" runat="server"
contentplaceholderid="ContentPlaceHolder2">
<table class="style8" cellpadding="3">
<tr>
<td class="style9">Add New Booth</td>
<td> </td>
</tr>
<tr>
<td class="style9"> </td>
<td> </td>
</tr>
<tr>
<td class="style9">Event Title:</td>
<td>
<asp:SqlDataSource ID="SqlDataSourceEventTitle" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>" SelectCommand="SELECT DISTINCT [eventID], [eventTitle] FROM [eventinfo]">
</asp:SqlDataSource>
<asp:DropDownList ID="ddlEventTitle" runat="server" DataSourceID="SqlDataSourceEventTitle" DataTextField="eventTitle" DataValueField="eventID" Width="240px" AutoPostBack="True">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style9">Booth Alias:</td>
<td>
<asp:TextBox ID="txtBoothAlias" runat="server" Width="235px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style9"> Booth Type:</td>
<td>
<asp:DropDownList ID="ddlBoothType" runat="server" Width="240px" AutoPostBack="True">
<asp:ListItem Value="7">8'x8'</asp:ListItem>
<asp:ListItem Value="10">9'x8'</asp:ListItem>
<asp:ListItem Value="11">12'x50'</asp:ListItem>
<asp:ListItem Value="12">16'x10'</asp:ListItem>
<asp:ListItem Value="13">20'x16'</asp:ListItem>
<asp:ListItem Value="15">32'x10'</asp:ListItem>
<asp:ListItem Value="17">32'x14.5'</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style10" valign="top" colspan="2">Booth Duration:<br />
<font size="2">Tick to activate availability</font></td>
</tr>
<tr>
<td class="style10" valign="top" colspan="2" align="center">
<asp:Panel ID="Panel1" runat="server" Width="328px" Direction="LeftToRight" HorizontalAlign="Center">
<table cellpadding="5" class="style8">
<tr>
<td>
<asp:CheckBox ID="cbWeek1" runat="server" Text="Week 1" TextAlign="Left" OnCheckedChanged="cbWeek1_CheckedChanged" AutoPostBack="true"/>
</td>
<td>
<asp:CheckBox ID="cbWeek2" runat="server" Text="Week 2" TextAlign="Left" OnCheckedChanged="cbWeek2_CheckedChanged" AutoPostBack="true"/>
</td>
<td>
<asp:CheckBox ID="cbWeek3" runat="server" Text="Week 3" TextAlign="Left" OnCheckedChanged="cbWeek3_CheckedChanged" AutoPostBack="true"/>
</td>
<td>
<asp:CheckBox ID="cbWeek4" runat="server" Text="Week 4" TextAlign="Left" OnCheckedChanged="cbWeek4_CheckedChanged" AutoPostBack="true"/>
</td>
</tr>
<tr>
<td>
<asp:CheckBox ID="cbWeek5" runat="server" Text="Week 5" TextAlign="Left" OnCheckedChanged="cbWeek5_CheckedChanged" AutoPostBack="true"/>
</td>
<td>
<asp:CheckBox ID="cbWeek6" runat="server" Text="Week 6" TextAlign="Left" OnCheckedChanged="cbWeek6_CheckedChanged" AutoPostBack="true"/>
</td>
<td>
<asp:CheckBox ID="cbWeek7" runat="server" Text="Week 7" TextAlign="Left" OnCheckedChanged="cbWeek7_CheckedChanged" AutoPostBack="true"/>
</td>
<td>
<asp:CheckBox ID="cbWeek8" runat="server" Text="Week 8" TextAlign="Left" OnCheckedChanged="cbWeek8_CheckedChanged" AutoPostBack="true"/>
</td>
</tr>
</table>
</asp:Panel>
<asp:RoundedCornersExtender ID="Panel1_RoundedCornersExtender"runat="server" Enabled="True" TargetControlID="Panel1" BorderColor="CadetBlue" Color="ButtonFace">
</asp:RoundedCornersExtender>
</td>
</tr>
<tr>
<td class="style11">
</td>
<td class="style11">
<asp:Button ID="ButtonAddNewBooth" runat="server" Text="Add New Booth" Height="50px" />
</td>
</tr>
<tr>
<td class="style9"> </td>
<td> </td>
</tr>
<tr>
<td class="style9" colspan="2">
<asp:GridView ID="GridViewBoothAdded" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSourceBoothAdded" Font-Size="Small" ForeColor="#333333" GridLines="None" AllowPaging="True" PageSize="5" Visible="False">
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:BoundField DataField="boothAlias" HeaderText="Booth Alias" SortExpression="boothAlias" />
<asp:BoundField DataField="week1" HeaderText="week1" SortExpression="week1" />
<asp:BoundField DataField="week2" HeaderText="week2" SortExpression="week2" />
<asp:BoundField DataField="week3" HeaderText="week3" SortExpression="week3" />
<asp:BoundField DataField="week4" HeaderText="week4" SortExpression="week4" />
<asp:BoundField DataField="week5" HeaderText="week5" SortExpression="week5" />
<asp:BoundField DataField="week6" HeaderText="week6" SortExpression="week6" />
<asp:BoundField DataField="week7" HeaderText="week7" SortExpression="week7" />
<asp:BoundField DataField="week8" HeaderText="week8" SortExpression="week8" />
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<EmptyDataTemplate>
No booth record
</EmptyDataTemplate>
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="Small" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
<asp:RoundedCornersExtender ID="GridViewBoothAdded_RoundedCornersExtender" runat="server" Enabled="True" TargetControlID="GridViewBoothAdded">
</asp:RoundedCornersExtender>
<asp:SqlDataSource ID="SqlDataSourceBoothAdded" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
SelectCommand="SELECT [week1], [week2], [week3], [week4], [week5], [week6], [week7], [week8], [eventID], [boothAlias], [eventTitle] FROM [booth_eventinfo] WHERE ([eventID] = #eventID)">
<SelectParameters>
<asp:ControlParameter ControlID="ddlEventTitle" Name="eventID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
</table>
server code:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Threading
Partial Class addbooth
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
GridViewBoothAdded.Visible = True
End Sub
Protected Sub ButtonAddNewBooth_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonAddNewBooth.Click
Dim connString As String = ConfigurationManager.ConnectionStrings("ConnectionString1").ConnectionString
'"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\eventdb.mdf;Integrated Security=True;User Instance=True"
Dim con As SqlConnection = New SqlConnection(connString)
Dim cmdQuery As String = "INSERT INTO booth(eventID,boothAlias,boothType,week1,week2,week3,week4,week5,week6,week7,week8) VALUES (#eventID,#boothAlias,#boothType,#week1,#week2,#week3,#week4,#week5,#week6,#week7,#week8)"
Dim cmd = New SqlCommand(cmdQuery)
cmd.Connection = con
cmd.CommandType = CommandType.Text
con.Open()
cmd.Parameters.AddWithValue("#eventID", ddlEventTitle.SelectedValue)
cmd.Parameters.AddWithValue("#boothAlias", txtBoothAlias.Text)
cmd.Parameters.AddWithValue("#boothType", ddlBoothType.SelectedValue)
If (cbWeek1.Checked = True) Then
cmd.Parameters.AddWithValue("#week1", "1")
Else
cmd.Parameters.AddWithValue("#week1", "0")
End If
If (cbWeek2.Checked = True) Then
cmd.Parameters.AddWithValue("#week2", "1")
Else
cmd.Parameters.AddWithValue("#week2", "0")
End If
If (cbWeek3.Checked = True) Then
cmd.Parameters.AddWithValue("#week3", "1")
Else
cmd.Parameters.AddWithValue("#week3", "0")
End If
If (cbWeek4.Checked = True) Then
cmd.Parameters.AddWithValue("#week4", "1")
Else
cmd.Parameters.AddWithValue("#week4", "0")
End If
If (cbWeek5.Checked = True) Then
cmd.Parameters.AddWithValue("#week5", "1")
Else
cmd.Parameters.AddWithValue("#week5", "0")
End If
If (cbWeek6.Checked = True) Then
cmd.Parameters.AddWithValue("#week6", "1")
Else
cmd.Parameters.AddWithValue("#week6", "0")
End If
If (cbWeek7.Checked = True) Then
cmd.Parameters.AddWithValue("#week7", "1")
Else
cmd.Parameters.AddWithValue("#week7", "0")
End If
If (cbWeek8.Checked = True) Then
cmd.Parameters.AddWithValue("#week8", "1")
Else
cmd.Parameters.AddWithValue("#week8", "0")
End If
GridViewBoothAdded.Visible = True
Can you move you GridView Data Binding Code to code behind file Page_Load Method & call the same code at the end of your ButtonAddNewBooth_Click event. That will serve your purpose.
Link: GridView.DataBind
I see in your ButtonAddNewBooth_Click method you are missing the ExecuteSql() for the sqlcommand and gridview bind code
After adding parameters to cmd add the following two lines one for executing the insert and the other for rebinding the grid
cmd.ExecuteSql()
GridViewBoothAdded.DataBind()