How to update gridview when upon click submit button? - asp.net

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()

Related

Page wont Load computed ASP WEB variable

How can I fix this form, I need to redirect the result to a different page after the button "Display offer is pressed"; the main problem here is that I can't save the data and redirecting it. The 2nd page should look something like this:
The price for the vehicle you have configured is [All the options selected/computed]
The offer was issued on [Calendar date1] and remains valid until [Calendar date2]
I have tested something using Cache...still no result.
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
GetData()
End Sub
1 reference
Private Sub GetData()
lblName.Text = Cache("Name").ToString
1blPrice.Text = Cache("Price").ToString
lblofferDate.Text = Cache("offerDate").ToString
1blofferExpiration.Text = Cache("ExpirationDate").ToString
End Sub
1st page - Main FORM.
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 100%;
}
.auto-style2 {
width: 204px;
}
.auto-style3 {
text-decoration: underline;
}
.auto-style4 {
width: 843px;
border-collapse: collapse;
}
.auto-style5 {
height: 24px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="auto-style1">
<tr>
<td class="auto-style2">
<asp:Label ID="Label1" runat="server" Text="Last Name:"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">
<asp:Label ID="Label2" runat="server" Text="First Name:"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">
<asp:Label ID="Label3" runat="server" Text="Offer date:"></asp:Label>
</td>
<td>
<asp:Calendar ID="calOfferDate" runat="server" BackColor="White" BorderColor="#999999" CellPadding="4" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" Height="180px" Width="200px">
<DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt" />
<NextPrevStyle VerticalAlign="Bottom" />
<OtherMonthDayStyle ForeColor="#808080" />
<SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" />
<SelectorStyle BackColor="#CCCCCC" />
<TitleStyle BackColor="#999999" BorderColor="Black" Font-Bold="True" />
<TodayDayStyle BackColor="#CCCCCC" ForeColor="Black" />
<WeekendDayStyle BackColor="#FFFFCC" />
</asp:Calendar>
</td>
</tr>
<tr>
<td class="auto-style2">
<asp:Label ID="Label4" runat="server" Text="Offer expiration date:"></asp:Label>
</td>
<td>
<asp:Calendar ID="calExpirationDate" runat="server" BackColor="White" BorderColor="#999999" CellPadding="4" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" Height="180px" Width="200px">
<DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt" />
<NextPrevStyle VerticalAlign="Bottom" />
<OtherMonthDayStyle ForeColor="#808080" />
<SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" />
<SelectorStyle BackColor="#CCCCCC" />
<TitleStyle BackColor="#999999" BorderColor="Black" Font-Bold="True" />
<TodayDayStyle BackColor="#CCCCCC" ForeColor="Black" />
<WeekendDayStyle BackColor="#FFFFCC" />
</asp:Calendar>
</td>
</tr>
</table>
<hr />
</div>
<p class="auto-style3">
<strong>Set up your car</strong></p>
<table class="auto-style4">
<tr>
<td class="auto-style5">
<asp:Label ID="Label5" runat="server" Text="Equipment level"></asp:Label>
</td>
<td class="auto-style5">
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="20,000">Standard</asp:ListItem>
<asp:ListItem Value="22,000">Evolved</asp:ListItem>
<asp:ListItem Value="27,000">Advanced</asp:ListItem>
<asp:ListItem Value="32,000">Premium</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label6" runat="server" Text="Warranty type"></asp:Label>
</td>
<td>
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem>Standard (2 years)</asp:ListItem>
<asp:ListItem>Extended (5 years)</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label7" runat="server" Text="Optionals"></asp:Label>
</td>
<td>
<asp:RadioButtonList ID="rblOptionals" runat="server" AutoPostBack="True">
<asp:ListItem Selected="True">Yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
</asp:RadioButtonList>
<asp:CheckBoxList ID="cblOptionals" runat="server" RepeatDirection="Horizontal" Width="727px">
<asp:ListItem Value="1,000">Alloys wheels</asp:ListItem>
<asp:ListItem Value="1,500">Climatronic</asp:ListItem>
<asp:ListItem Value="1,300">Automatic pilot</asp:ListItem>
<asp:ListItem Value="1,000">Road alert</asp:ListItem>
<asp:ListItem Value="850">Navigation</asp:ListItem>
</asp:CheckBoxList>
</td>
</tr>
<tr>
<td class="auto-style5">
<asp:Label ID="Label8" runat="server" Text="Discounts"></asp:Label>
</td>
<td class="auto-style5"><strong><em>
<asp:CheckBoxList ID="cbListDiscounts" runat="server" RepeatDirection="Horizontal" CssClass="auto-style5" Width="394px" TextAlign="Left">
<asp:ListItem>Whole payment</asp:ListItem>
<asp:ListItem>CASCO insurance</asp:ListItem>
</asp:CheckBoxList>
</em></strong></td>
</tr>
<tr>
<td> </td>
<td>
<asp:Button ID="btnDisplayOffer" runat="server" BackColor="Red" ForeColor="#CCCCCC" Height="20px" Text="Display offer" Width="101px" />
</td>
</tr>
</table>
</form>
</body>
</html>
Display button in FORM
Public Class WebForm1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub btnDisplayOffer_Click(sender As Object, e As EventArgs) Handles btnDisplayOffer.Click
Response.Redirect("Offer.aspx")
End Sub
Public Sub CreateCache()
Cache("Name") = txtFirstName.Text & " " & txtLastName.Text
Cache("offerDate") = calOfferDate.SelectedDate
Cache("ExpirationDate") = calExpirationDate.SelectedDate
Dim price As Integer
If DropDownList1.Items(0).Selected = True Then
price = 20000
ElseIf DropDownList1.Items(1).Selected = True Then
price = 22000
ElseIf DropDownList1.Items(2).Selected = True Then
price = 27000
Else
price = 32000
End If
If RadioButtonList1.Items(1).Selected = True Then
price = price + 2000
End If
If cbListDiscounts.Items(0).Selected = True Then
price = price - (price * 0.1)
End If
If cbListDiscounts.Items(1).Selected = True Then
price = price - 1000
End If
End Sub
Protected Sub rblOptionals_SelectedIndexChanged(sender As Object, e As EventArgs) Handles rblOptionals.SelectedIndexChanged
If rblOptionals.SelectedValue.Equals("Yes") Then
cblOptionals.Visible = True
Else
cblOptionals.Visible = False
End If
End Sub
End Class
Just code out your button code. You click on that button - it saves some data, and then does a simple response.Redirect.
Protected Sub btnDisplayOffer_Click(sender As Object, e As EventArgs) Handles btnDisplayOffer.Click
SaveMyData
Response.Redirect("Offer.aspx")
End Sub
Sub SaveMyData
Session("Name") = txtFirstName.Text & " " & txtLastName.Text
Session("offerDate") = calOfferDate.SelectedDate
Session("ExpirationDate") = calExpirationDate.SelectedDate
.etc .etc. etc.
End Sub
Now, in the target page, you can in on-load do this:
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
if IsPostBack = False then
GetData()
end if
End Sub
Private Sub GetData()
lblName.Text = Session("Name")
1blPrice.Text = Session("Price")
lblofferDate.Text = Session("offerDate")
1blofferExpiration.Text = Session("ExpirationDate")
End Sub
and as noted always remember to check IsPostPack = False. That is your FIRST one time page load - so inside of that code block then becomes just like say a VB6 or ms-access form load event - the first time is where your load up code goes - without that if IsPostBack = False, then that code will run every time - including for buttons etc. that you drop on the form - and thus those controls will be re-set each time you use a button or any event on that page - as a coding habit - put your page load up code inside of the IsPostBack=False code stub - do NOT forget to have that code block - make it habit - even when you think you don't need to!!!!

DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'p'

I am getting an error DataBinding: "'System.Data.DataRowView' does not contain a property with the name 'p'" in one query within the following code.
It shows error in this line:
<asp:Label ID="lblPharmName" runat="server" Text='<%# String.Format("{0} {1}", Eval("p.Pharm_fname"), Eval("p.Pharm_lname")) %>'>
</asp:Label>
Below is the code. But I am suspecting the query used. Any suggestion will be appreciated in finding what is causing the error to be returned.
Thank you
<%# Page Language="VB" MasterPageFile="~/CIOSMasterNonAuth.master" AutoEventWireup="false" CodeFile="ViewOrders.aspx.vb" Inherits="ViewOrders" title="Untitled Page" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<%--<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>--%>
<asp:Table runat="server" Font-Size="Small" HorizontalAlign="Center">
<asp:TableRow>
<asp:TableCell HorizontalAlign="Right">
<asp:Label runat="server">Order Status: </asp:Label>
</asp:TableCell>
<asp:TableCell HorizontalAlign="Left">
<asp:DropDownList ID="OrderStatusDropDownList" runat="server" AutoPostBack="True">
<asp:ListItem Text="Verified" Value="V" />
<asp:ListItem Text="New" Value="N" />
<asp:ListItem Text="Cancelled" Value="C" />
</asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell ColumnSpan="2">
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<HeaderTemplate>
<table border="1" visible="false">
<tr>
<th>
Web Order ID
</th>
<th>
Web Entry Date
</th>
<th>
Protocol Number
</th>
<th>
Site Number
</th>
<th>
Pharmacist of Record
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:LinkButton runat="server" ID="lnkOrderDetails" Text='<%# Eval("web_order_id") %>' OnClick="lnkOrderDetails_Click" />
</td>
<td>
<asp:Label ID="lblWebEntryDate" runat="server" Text='<%# Eval("web_entry_date") %>'>
</asp:Label>
</td>
<td>
<asp:Label ID="lblProtocolNum" runat="server" Text='<%# Eval("protocol_num") %>'>
</asp:Label>
</td>
<td>
<asp:Label ID="lblSiteNum" runat="server" Text='<%# Eval("site_num") %>'>
</asp:Label>
</td>
<td>
<asp:Label ID="lblPharmName" runat="server" Text='<%# String.Format("{0} {1}", Eval("p.Pharm_fname"), Eval("p.Pharm_lname")) %>'>
</asp:Label>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<asp:Button runat="server" ID="btnShowModalPopup" style="display:none"/>
<cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
TargetControlID="btnShowModalPopup"
PopupControlID="divPopUp"
PopupDragHandleControlID="panelDragHandle">
</cc1:ModalPopupExtender>
<div id="divPopUp" style="display:none; font-family:Georgia; font-size:small;">
<asp:Panel runat="Server" ID="panelDragHandle" BackColor="#009999" BorderColor="ActiveBorder" BorderStyle="Ridge" ForeColor="White" Width="800px">
<table width="100%">
<tr>
<td>
Hold here to Drag this Box
</td>
<td align="right">
<asp:Label runat="server" ID="lblText" Text="Web OrderID: " ForeColor="White"></asp:Label>
<asp:Label ID="lblWebOrderID" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td colspan="2">
<asp:GridView ID="GridView2" runat="server" BackColor="#FFFFCC" ForeColor="Black" AutoGenerateColumns="False" Width="100%" >
<Columns>
<asp:BoundField DataField="line_id" HeaderText="Line Item"/>
<asp:BoundField DataField="no_of_participants" HeaderText="Number of Participants" />
<asp:BoundField DataField="amt_inventory" HeaderText="Current Inventory"/>
<asp:BoundField DataField="nsc_num" HeaderText="NSC number"/>
<asp:BoundField DataField="drug_name" HeaderText="Drug name"/>
<asp:BoundField DataField="dose_str" HeaderText="Dose Strength"/>
<asp:BoundField DataField="dose_unit" HeaderText="Dose Unit"/>
<asp:BoundField DataField="dose_form_comment" HeaderText="Dose Form"/>
<asp:BoundField DataField="dose_mult" HeaderText="Dose Mult" />
<asp:BoundField DataField="amt_req" HeaderText="Amt Required"/>
</Columns>
</asp:GridView>
</td>
</tr>
<tr>
<td colspan="2" align="right">
<asp:Button ID="btnClose" runat="server" Text="Close" />
</td>
</tr>
</table>
</asp:Panel>
<br />
</div>
<%
Response.AddHeader("Refresh", "60")
%>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CIOSConnectionString3 %>"
SelectCommand="SELECT w.web_order_id, w.web_entry_date, w.site_num, w.protocol_num, w.inv_num, w.pharm_num, w.status, w.Comments, w.UserName, w.porStatus, p.Pharm_fname + ' ' + p.Pharm_lname AS 'PharmName' FROM Web_Shipping AS w INNER JOIN Pharmacist_of_record AS p ON p.pharm_num = w.pharm_num WHERE (w.status = #status) ORDER BY w.web_order_id DESC" >
<SelectParameters>
<asp:ControlParameter ControlID="OrderStatusDropDownList" Name="Status"
PropertyName="Text" Type="Char" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:CIOSConnectionString3 %>"
SelectCommand="SELECT Web_Ship_detail.line_id, Web_Ship_detail.no_of_participants, Web_Ship_detail.Amt_inventory, Web_Ship_detail.NSC_num, Web_Ship_detail.Dose_str, Web_Ship_detail.Dose_unit, Web_Ship_detail.Dose_mult, Web_Ship_detail.amt_req, Drug.Drug_name, Dosage_Form.dose_form_comment FROM Web_Ship_detail INNER JOIN Drug ON Web_Ship_detail.NSC_num = Drug.NSC_Num INNER JOIN Dosage_Form ON Web_Ship_detail.Dose_form = Dosage_Form.dose_form WHERE (Web_Ship_detail.web_order_id = #web_order_id) ORDER BY Web_Ship_detail.line_id">
<SelectParameters>
<asp:ControlParameter ControlID="lblWebOrderID" Name="web_order_id"
PropertyName="Text" Type="Decimal" />
</SelectParameters>
</asp:SqlDataSource>
These
Eval("p.Pharm_fname"), Eval("p.Pharm_lname")
Do not exist in your select
p.Pharm_fname + ' ' + p.Pharm_lname AS 'PharmName'
You need to update either your Eval to evaluate PharmName or SQL to include p.Pharm_fname and p.Pharm_lname and get rid of the alias reference in the Eval.

HTML formatting changes when the page is not full screen

I have an aspx page, which looks like this:
When I restore the window, the layout changes to look like this:
How do I stop this from happening? My code is below:
<%# Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
Debug="true" CodeFile="MAIN.aspx.cs" Inherits="MAIN" %>
<script type="text/javascript">
var validFilesTypes = ["jpg", "JPG", "png", "PNG", "jpeg", "gif", "GIF"];
function CheckExtension(file) {
/*global document: false */
var lbl = document.getElementById('<%=lblMessage.ClientID %>');
lbl.innerHTML = "";
var filePath = file.value;
var ext = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase();
var isValidFile = false;
for (var i = 0; i < validFilesTypes.length; i++) {
if (ext == validFilesTypes[i]) {
isValidFile = true;
break;
}
}
if (!isValidFile) {
file.value = null;
lbl.innerHTML = "Only jpg, png and gif allowed";
// alert("Invalid File. Valid extensions are:\n\n" + validFilesTypes.join(", "));
return false;
}
return isValidFile;
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
<ajaxToolkit:ToolkitScriptManager EnablePartialRendering="true" runat="Server" ID="ScriptManager1" />
<br />
Change Location
<br />
<br />
<div id="divSearch" style="width: 100%; height: 35px">
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<asp:TextBox ID="txtSearch" runat="server" Width="50%"
Height="100%"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Height="100%" Text="Search" CausesValidation="false"
OnClick="btnSearch_Click" />
<ajaxToolkit:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender2" WatermarkText="Enter street followed by City"
runat="server" TargetControlID="txtSearch" />
<asp:AdRotator style="margin-left:250px" id="CAdRotator" runat="server" AdvertisementFile="AdRotatorFiles.xml"
Width="200px" Height="100%" Target="_blank"></asp:AdRotator>
</div>
<br />
<asp:Label ID="lblMsg" runat="server" Text="aa" Width="1%" Visible="false"></asp:Label>
<div style="overflow:hidden;">
<input type="hidden" runat="server" id="hcheckQuery" />
<div style="width:80%; float:left;">
<table>
<tr>
<td valign="top">
<table>
<tr>
<td>
<asp:GridView ID="RepDetails" style="float:none" OnRowDataBound="RowDataBound" OnRowCreated="RowCreated" Width="100%" runat="server" AutoGenerateColumns="False" BackColor="White"
BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px">
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<div id="divPost" style="float: right;">
<div>
<asp:Label ID="lblMessage" runat="server" ForeColor="Red"></asp:Label> </div>
<table width="100%" class="imagetable">
<tr>
<td>
Province<asp:DropDownList ID="ddlProvince" CssClass="font1" runat="server" Width="90%">
<asp:ListItem Text="---Select---" Value="-1"></asp:ListItem>
<asp:ListItem Text="Alberta" Value="1" Selected="True"></asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="ddlProvince"
InitialValue="-1" ErrorMessage="*" ValidationGroup="g1"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
City<br />
<asp:DropDownList ID="ddlCity" CssClass="font1" runat="server" Width="90%">
<asp:ListItem Text="---Select---" Value="-1"></asp:ListItem>
<asp:ListItem Text="Edmonton" Value="1" Selected="True"></asp:ListItem>
<asp:ListItem Text="Calgary" Value="2"></asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="ddlCity"
InitialValue="-1" ErrorMessage="*" ValidationGroup="g1"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Description<asp:TextBox ID="txtDescription" CssClass="font1" TextMode="MultiLine"
runat="server" Width="90%"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="txtDescription"
ErrorMessage="*" ValidationGroup="g1"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Address<asp:TextBox ID="txtAddress" CssClass="font1" TextMode="MultiLine" runat="server"
Width="90%"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtAddress"
ErrorMessage="*" ValidationGroup="g1"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Rent (CAD)<asp:TextBox ID="txtRent" CssClass="font1" runat="server" Width="90%"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtRent"
ErrorMessage="*" ValidationGroup="g1"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtRent"
ErrorMessage="*" ValidationExpression="\d+" ValidationGroup="g1">
</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>
Email<asp:TextBox ID="txtEmail" CssClass="font1" runat="server" Width="90%"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="txtEmail"
ErrorMessage="*" ValidationGroup="g1"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Phone<asp:TextBox ID="txtPhone" CssClass="font1" runat="server" Width="90%"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="txtPhone"
ErrorMessage="*" ValidationGroup="g1"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Image<asp:FileUpload ID="fuImage" runat="server" onchange="return CheckExtension(this);" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" CssClass="font1" runat="server" BackColor="DarkKhaki"
Text="Submit" ValidationGroup="g1" OnClick="btnSubmit_Click" />
</td>
</tr>
</table>
<br />
<br />
<br />
<br />
<br />
<div style="border-style:solid; border-color:Lime">
<asp:Label ID="lblHits" runat="server" ></asp:Label>
</div>
</div>
</div>
I've tried min-width, but that didn't work.
All I had to do was to add resize jquery
Something like this
$(window).resize(function() {
if ($(window).width() <= 1200)
$("body").css("width", "130%");
else
$("body").css("width", "100%");
});

ASP.Net VB File Upload

I am making an ASP.Net VB web application and I am trying to upload files to the server. There is a modal popup and inside of the popup it will display an image if it exists, If it does not exist you can upload an image. The trouble is that Whenever I hit the upload button no file uploads. The page refreshes and the popup disappears. I just want it so at least the file uploads properly.
This is the asp code for the pop up
<div id="openModal" class="modalDialog">
<div>
X
<h2>Transaction Recipt</h2>Transaction ID:
<asp:Label ID="Label2" runat="server" Text=''></asp:Label>
<br /><br />
<asp:Image ID="Image1" runat="server" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br /><br />
<br />
<asp:FileUpload id="FileUploadControl" runat="server" />
<br /><br />
<asp:Button ID="Button2" runat="server" Text="Upload" OnClick = "Button_Upload" CommandArgument = '<%# Eval("Row") %>' Width="75" /><br>
<asp:Label ID="Label3" runat="server" Text=""></asp:Label>
</div>
This is the vb code for the file upload
Protected Sub Button_Upload(ByVal sender As Object, ByVal e As EventArgs)
If FileUploadControl.HasFile Then
Try
FileUploadControl.SaveAs("~\Images\" & _
FileUploadControl.FileName)
Label1.Text = "File name: " & _
FileUploadControl.PostedFile.FileName & "<br>" & _
"File Size: " & _
FileUploadControl.PostedFile.ContentLength & " kb<br>" & _
"Content type: " & _
FileUploadControl.PostedFile.ContentType
Catch ex As Exception
Label1.Text = "ERROR: " & ex.Message.ToString()
End Try
Else
Label1.Text = "You have not specified a file."
End If
End Sub
And this is the asp code for the whole page in case you need it
<%# Page Title="" Language="VB" MasterPageFile="~/Admin.master" AutoEventWireup="false"
CodeFile="Ledger.aspx.vb" Inherits="Admin_Accounting_Ledger" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
<link href="../../Styles/Admin.css" rel="Stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [Account] FROM [Accounts]"></asp:SqlDataSource>
<table style="width:100%;">
<tr>
<td class="style1">
<asp:DropDownList ID="DropDownList1" runat="server" ViewStateMode="Enabled"
Width="241px" AutoPostBack="True" DataSourceID="SqlDataSource1"
DataTextField="Account" DataValueField="Account">
</asp:DropDownList>
<br />
</td>
<td class="style2">
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px"
CellPadding="2" DataSourceID="SqlDataSource3" ForeColor="Black"
GridLines="None" Height="30px" Width="241px">
<AlternatingRowStyle BackColor="PaleGoldenrod" />
<EditRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<Fields>
<asp:BoundField DataField="Column1" HeaderText="Account Total" ReadOnly="True"
SortExpression="Column1" />
</Fields>
<FooterStyle BackColor="Tan" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue"
HorizontalAlign="Center" />
</asp:DetailsView>
</td>
<td>
<asp:Button ID="Button1" runat="server" Text="Add Transaction"
BackColor="#CCCCCC" />
</td>
</tr>
<tr>
<td class="style1">
</td>
<td class="style2">
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
</td>
<td class="style2">
</td>
<td>
</td>
</tr>
</table>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT SUM(Amount) FROM Transactions WHERE ([Account] LIKE '%' + #Account + '%')">
<SelectParameters>
<asp:QueryStringParameter Name="Account" QueryStringField="id" />
</SelectParameters>
</asp:SqlDataSource>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource2">
<ItemTemplate>
<table style="width: 100%;">
<tr>
<td align="center" width="150px">
<%# Eval("Date")%>
</td>
<td align="center" width="200px">
<%# Eval("Category")%>
</td>
<td align="center" >
<%# Eval("Amount")%>
</td>
<td align="Right" >
<asp:Button ID="Button2" runat="server" Text="Reciept" OnClick = "Button_Reciept" CommandArgument = '<%# Eval("Row") %>' Width="75" /><br>
</td>
</tr>
</table>
<br/>
</ItemTemplate>
</asp:Repeater>
<div id="openModal" class="modalDialog">
<div>
X
<h2>Transaction Recipt</h2>Transaction ID:
<asp:Label ID="Label2" runat="server" Text=''></asp:Label>
<br /><br />
<asp:Image ID="Image1" runat="server" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br /><br />
<br />
<asp:FileUpload id="FileUploadControl" runat="server" />
<br /><br />
<asp:Button ID="Button2" runat="server" Text="Upload" OnClick = "Button_Upload" CommandArgument = '<%# Eval("Row") %>' Width="75" /><br>
<asp:Label ID="Label3" runat="server" Text=""></asp:Label>
</div>
</div>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [Date], [Amount], [Category], [Row] FROM [Transactions] WHERE ([Account] LIKE '%' + #Account + '%') ORDER BY Date DESC">
<SelectParameters>
<asp:QueryStringParameter Name="Account" QueryStringField="id" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</asp:Content>
Thank you
1- If you are using an update panel you should use post back trigger.
2- In code behind you should use view state (Property) to store the file name and path then add it to your DB.
3- In your case i think that there is a place you are posting back the page after selecting uploaded file -trace the code-
basically you can save only the extension on the DB, and the image it self on the solution, so you can call it as you said.. you can do something like (code am using for employee images)
If .EmpImagePath <> Nothing Then
FileFullPath = .EmpImagePath
Dim imgURL As String = Convert.ToBase64String(ConvertImageFiletoBytes(.EmpImagePath))
Dim imgSrc As String = String.Format("data:/image/gif;base64,{0}", imgURL)
EmpImg.ImageUrl = imgSrc
Else
If .Gender = "f" Then
EmpImg.ImageUrl = "~/images/no_photo_female.jpg"
Else
EmpImg.ImageUrl = "~/images/nophoto.jpg"
End If
End If

Open user control in ModalPopUpExtender when text box is clicked

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();"

Resources