ASP.Net VB File Upload - asp.net

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

Related

ASP.NET Webforms Error When Trying to Update SQL Data

my question is about how to go about updating data in a ASP.NET listview using a stored procedure.
I'm getting an error message whenever I try to update any data in my listview stating that my stored procedure has too many arguments specified.
I've looked through all of my code and all of my arguments seem to match up with my stored procedure so I think it might have to do with how I created the listview (just dragging and dropping it in design view using visual studio 2015) or it's something wrong with my stored procedure.
I've been stuck on this issue for about a day now and I feel like I'm missing something real simple here but can't quite put my finger on it.
If anyone could help my out I would greatly appreciate it. This app I'm working on uses vb.net as it's back-end and used ASP.NET web forms. Below is the code for the page I'm working on.
ASP.NET Page (Might not work properly since it uses a master page and some other external resources)
<%# Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/MasterPages/MasterPage.Master" CodeBehind="CodeManagement.aspx.vb" Inherits="OcasNS.CodeManagement" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolderInHead" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="CPH1_DontUseInAContentPageItsJustForTheseJavaScriptFiles" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<p>Course Code:<asp:TextBox ID="TextBox1" runat="server" Height="18px"></asp:TextBox>
</p>
<br />
<p>Course Title:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</p>
<br />
<p>Class/Group:<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
</p>
<p>Career Tech Course Type:
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
</p>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:OKECSTestConnectionString %>" SelectCommand="spCodeManagementLookup" SelectCommandType="StoredProcedure" UpdateCommand="spCodeManagementUpdate" UpdateCommandType="StoredProcedure">
<UpdateParameters>
<asp:Parameter Name="ClassGroupID" Type="Int32" />
<asp:Parameter Name="CourseDescription" Type="String" />
<asp:Parameter Name="ClassSubjectCode" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:ListView ID="ListView1" runat="server" DataKeyNames="ClassGroupID" DataSourceID="SqlDataSource1">
<AlternatingItemTemplate>
<tr style="background-color:#FFF8DC;">
<td>
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="ClassGroupIDLabel" runat="server" Text='<%# Eval("ClassGroupID") %>' />
</td>
<td>
<asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>' />
</td>
<td>
<asp:Label ID="ClassSubjectCodeLabel" runat="server" Text='<%# Eval("ClassSubjectCode") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<EditItemTemplate>
<tr style="background-color:#008A8C;color: #FFFFFF;">
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
<td>
<asp:Label ID="ClassGroupIDLabel1" runat="server" Text='<%# Eval("ClassGroupID") %>' />
</td>
<td>
<asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>' />
</td>
<td>
<asp:TextBox ID="ClassSubjectCodeTextBox" runat="server" Text='<%# Bind("ClassSubjectCode") %>' />
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<table runat="server" style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;">
<tr>
<td>No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
</td>
<td> </td>
<td>
<asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>' />
</td>
<td>
<asp:TextBox ID="ClassSubjectCodeTextBox" runat="server" Text='<%# Bind("ClassSubjectCode") %>' />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr style="background-color:#DCDCDC;color: #000000;">
<td>
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="ClassGroupIDLabel" runat="server" Text='<%# Eval("ClassGroupID") %>' />
</td>
<td>
<asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>' />
</td>
<td>
<asp:Label ID="ClassSubjectCodeLabel" runat="server" Text='<%# Eval("ClassSubjectCode") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table id="itemPlaceholderContainer" runat="server" border="1" style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;">
<tr runat="server" style="background-color:#DCDCDC;color: #000000;">
<th runat="server"></th>
<th runat="server">ClassGroupID</th>
<th runat="server">Description</th>
<th runat="server">ClassSubjectCode</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="text-align: center;background-color: #CCCCCC;font-family: Verdana, Arial, Helvetica, sans-serif;color: #000000;">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False" />
<asp:NumericPagerField />
<asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr style="background-color:#008A8C;font-weight: bold;color: #FFFFFF;">
<td>
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="ClassGroupIDLabel" runat="server" Text='<%# Eval("ClassGroupID") %>' />
</td>
<td>
<asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>' />
</td>
<td>
<asp:Label ID="ClassSubjectCodeLabel" runat="server" Text='<%# Eval("ClassSubjectCode") %>' />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
<br />
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ShowEditButton="True" />
</Columns>
<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>
<br />
<br />
<button type="button">Save</button>
<button type="button">Cancel</button>
<button type="button">Export To Excel</button>
</asp:Content>
Update Stored Procedure (The one causing the error)
#ClassGroupID INT,
#CourseDescription VARCHAR(100),
#ClassSubjectCode VARCHAR(20)
UPDATE [dbo].[tb_oecs_CodeClassGroup]
SET [Description] = #CourseDescription
, [ClassSubjectCode] = #ClassSubjectCode
WHERE ClassGroupID = #ClassGroupID
Lookup Stored Procedure (This loads the data into the Listview)
SELECT DISTINCT
g.ClassGroupID
,g.Description
,g.ClassSubjectCode
FROM tb_oecs_CodeClassGroup g
JOIN tb_oecs_CodeClass c
ON g.ClassGroupID = c.ClassGroupID
ORDER BY g.ClassGroupID

How to set ID for Buttons in asp.net dynamically?

I wrote this code for set id for buttons by reading a field from db connected to sqldatasource,but the error say that I can set id like ID="btn1". but this is static. what should I do?
<asp:Button ID='<%# Eval("num") %>' runat="server" cssclass=btnd OnClick="delete_kala" />
this code is in datalist connected to sqldatasource.
codes for reading data from db:
<table class="cart-table">
<tr>
<td width=450>
<asp:Label ID="kalanameLabel" runat="server" Text='<%# Eval("kalaname") %>'/>
<asp:Label ID="kaladetailLabel" runat="server" Text='<%# Eval("kaladetail") %>'/>
<br />
</td>
<td width=100>
<asp:Label ID="kalapriceLabel" runat="server" Text='<%# Eval("kalaprice") %>' ForeColor=Green />
<asp:Label ID="Label1" runat="server" Text='تومان' />
<br />
</td>
<td>
<asp:Label ID="numLabel" runat="server" Text='<%# Eval("num") %>' />
<asp:Label ID="Label2" runat="server" Text='عدد' />
<br />
</td>
<td>
<asp:Button ID='<%# Eval("num") %>' runat="server" cssclass=btnd OnClick="delete_kala" />
<%-- <img src="images/delete.png" width="20" height=20 /> --%>
<br> </br></td>
<td>
<asp:Button ID="ed" runat="server" cssclass=btne OnClick="edit_kala"/>
<%-- <img src="images/edit.png" width=20 height=20 /> --%>
<br> </br></td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:onlineshopConnectionString %>" SelectCommand="
SELECT userid, kalaidbuy, num,kalaname,kaladetail,kalaprice
FROM cart inner join kala on
cart.kalaidbuy=kala.kalaID
where userid=#d "
>
<SelectParameters>
<asp:QueryStringParameter Name="d" QueryStringField="UID" />
</SelectParameters>
</asp:SqlDataSource>

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.

update gridview field without dataBind

i have a gridview that show comments. i want that if a person likes a comment, press a like button and i increse the sum of likes , but i do not want to connect to database and bind. i want do that using ajax. how can i do that?
here is my code:
<asp:UpdatePanel runat="server" id="UpdatePanel" >
<ContentTemplate>
<asp:GridView ID="grdCommentsForLoginnedUser"
runat="server"
AutoGenerateColumns="False"
Width="100%"
OnRowCommand="grdCommentsForLoginnedUser_RowCommand"
ViewStateMode="Inherit">
<Columns>
<asp:TemplateField >
<ItemTemplate>
<asp:HiddenField ID="hdnCommentID" runat="server"
Value='<%# Bind("CommentID") %>'/>
<table border="2" dir="rtl">
<tr>
<td rowspan="2" style="background-color: #6699FF" width="200px">
<asp:HyperLink ID="lnkCommenterName"
runat="server"
NavigateUrl='<%# Bind("CommenterProfile") %>'
Text='<%# Bind("CommenterName") %>' />
</td>
<td width="700px">
<br />
<asp:Label ID="lblCommentText" runat="server"
Text='<%# Bind("CommentText") %>' />
<br />
</td>
</tr>
<tr>
<td width="700px">
<asp:Label ID="lblPreviousAcceptOrNonAccept" runat="server"
Text='<%# Bind("PersonPreviousAcceptOrNonAccept") %>' />
<asp:LinkButton ID="lnkBtnRemovePreviousAcceptOrNonAccept"
runat="server"
Text='<%# Bind("RemovePersonPreviousAcceptOrNonAccept") %>'
CommandName="RemovePreviousAcceptOrNonAccept"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
<br />
<asp:LinkButton ID="lnkBtnUpRate" runat="server" Text="Like"
Visible='<%# Bind("isLikeAndUnlikeButtonVisible") %>'
CommandName="LikeComment"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
<br />sum of likes
<asp:Label ID="lblCommentLikes" runat="server"
Text='<%# Bind("CommentLikes") %>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
Add a client side onClick javascript to each button. When clicked get the parent td tag and then getElementById("lblCommentLikes") to set the .innerText property of the "lblCommentLikes" span.
+(theTD.getElementById("lblCommentLikes").innerText)+=1;
or
+(theTD.getElementById("lblCommentLikes").innerText)-=1;
Tip: If you are using IE then press F12 to inspect the DOM of a running page

Modal Popup Error

I have a DataList that has a link button and I want this link button envoke a modal popup. I've copied the mpe code from another application where it works in a gridview. The error is thrown as soon as page is openned and each time the link button is clicked. The error is thrown in the ScriptResource file: "Microsoft JScript runtime error: Sys.ArgumentNullException: Value cannot be null.
Parameter name: elements". I understand something has null value but not sure what. Page has over a thousand lines so I'll just paste the part I'm working on.
<ItemTemplate>
<tr class="AssetMngnt-trHeaderRow_bgColor">
<td valign="top">
<asp:Label ID="lblIdent" runat="server" Text='<%# Eval("Printer_Ident") %>' Visible="false"></asp:Label>
</td>
<td>
<asp:LinkButton ID="lbEdit" runat="server" CausesValidation="False" CommandName="Select" Text="Edit" />
</td>
<td valign="top" nowrap>
<asp:Label ID="lblName" Text='<%# Eval("Network_Name") %>' runat="server" />
</td>
<td valign="top">
<asp:LinkButton ID="lbPrinterModel"
runat="server" CausesValidation="False" CommandName="Select" CommandArgument="ShowAsset"
Text='<%# Eval("Printer_Mfg") + " " + (string)Eval("Printer_Model") %>' />
</td>
<td valign="top">
<asp:Label ID="lblLocation" Text='<%# Eval("Location") %>' runat="server" />
</td>
<td>
<asp:LinkButton ID="LinkButton1"
runat="server" CausesValidation="False" CommandName="Select" CommandArgument="IssueToners"
Text="Issue Toners" />
<asp:Button runat="server" ID="btnShowPopup" style="display:none" />
<ajaxToolkit:ModalPopupExtender runat="server" id="mpeIssueToners"
TargetControlID="btnShowPopup"
PopupControlID="pnlFvIssueTonersModal"
CancelControlID="UpdateCancelButton"
BackgroundCssClass="modalBackground" >
</ajaxToolkit:ModalPopupExtender>
</td>
</tr>
</ItemTemplate>
<asp:Panel runat="server" ID="pnlFvIssueTonersModal" Visible="true" style="display:none">
<asp:Panel runat="server" ID="pnlFvIssueToners" Visible="true">
<div id="AssetMngnt-FloatLeft_alt"">
<!-- ISSUE TONERS FORM VIEW ******************************************************************************** -->
<asp:FormView ID="fvIssueCartridges" runat="server" DataSourceID="ODSIssueCartridges"
OnItemUpdating="fvIssueCartridges_OnItemUpdating" OnItemUpdated="FormView1_Display_Update_Msg"
EnableViewState="False"
EmptyDataRowStyle-CssClass="AssetMngnt-panelRO" >
<EditItemTemplate>
</EditItemTemplate>
</asp:FormView>
<!-- END ISSUE TONERS FORM VIEW **************************************************************************** -->
</div>
</asp:Panel>
<ajaxToolKit:ModalPopupExtender ID="ModalPopupExtender1" BehaviorID="mdlPopup" runat="server"
TargetControlID="div" PopupControlID="div" CancelControlID="btnNo"
OnCancelScript="cancelClick();" BackgroundCssClass="modalBackground" />
<div id="div" runat="server" align="center" class="confirm" style="display:none">
<asp:Label Text="Form is empty - empty records are not allowed."
ForeColor="#000000" runat="server" ID="Label3" /><br />
<asp:Button ID="btnNo" runat="server" Text="Ok" Width="50px" />
</div>
</asp:Panel>
The ModalPopupExtender1 takes care of things inside the FormView.
Thanks,
Risho

Resources