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

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>

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

Delete\Update\Insert item in ListView

I have a ListView which has many templates (InsertItemTemplate, AlternatingItemTemplate, EditItemTemplate, EmptyDataTemplate, ItemTemplate, LayoutTemplate, SelectedItemTemplate)
I have this datasource:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:CouncilsConnectionString %>"
SelectCommand="SELECT [EmpID], [EmpName], [UserName], [password], [Email], [Mobile] FROM [Emp] WHERE ([FlageDel] = #FlageDel)"
DeleteCommand="DELETE FROM Emp WHERE (EmpId = #did)"
InsertCommand="INSERT INTO Emp(EmpName, UserName, password, Email, Mobile) VALUES (#inm, #ius, #ips, #iem, #imob)"
UpdateCommand="UPDATE Emp SET EmpName = #ename, UserName = #nm, password = #ps, Email = #em, Mobile = #mob WHERE (EmpId = #eid)">
<DeleteParameters>
<asp:Parameter Name="did" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="inm" />
<asp:Parameter Name="ius" />
<asp:Parameter Name="ips" />
<asp:Parameter Name="iem" />
<asp:Parameter Name="imob" />
</InsertParameters>
<SelectParameters>
<asp:Parameter DefaultValue="0" Name="FlageDel" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="ename" />
<asp:Parameter Name="nm" />
<asp:Parameter Name="ps" />
<asp:Parameter Name="em" />
<asp:Parameter Name="mob" />
<asp:Parameter Name="eid" />
</UpdateParameters>
</asp:SqlDataSource>
And in the ItemTemplate I have
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Update" />
</td>
I want to know how can I associate the delete button with the data source command so that it deletes the item when the button is clicked. The same thing for update\insert operations.
Here is the entire ListView Code
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" InsertItemPosition="LastItem">
<AlternatingItemTemplate>
<tr style="background-color: #FFFFFF;color: #000000;">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" CommandArgument="#did" Text="حذف" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="تعديل" />
</td>
<td>
<asp:Label ID="EmpNameLabel" runat="server" Text='<%# Eval("EmpName") %>' />
</td>
<td>
<asp:Label ID="UserNameLabel" runat="server" Text='<%# Eval("UserName") %>' />
</td>
<td>
<asp:Label ID="passwordLabel" runat="server" Text='<%# Eval("password") %>' />
</td>
<td>
<asp:Label ID="EmailLabel" runat="server" Text='<%# Eval("Email") %>' />
</td>
<td>
<asp:Label ID="MobileLabel" runat="server" Text='<%# Eval("Mobile") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<EditItemTemplate>
<tr style="background-color: #999999;">
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" CommandArgument="#eid" Text="حفظ" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="إلغاء" />
</td>
<td>
<asp:TextBox ID="EmpNameTextBox" runat="server" Text='<%# Bind("EmpName") %>' />
</td>
<td>
<asp:TextBox ID="UserNameTextBox" runat="server" Text='<%# Bind("UserName") %>' />
</td>
<td>
<asp:TextBox ID="passwordTextBox" runat="server" Text='<%# Bind("password") %>' />
</td>
<td>
<asp:TextBox ID="EmailTextBox" runat="server" Text='<%# Bind("Email") %>' />
</td>
<td>
<asp:TextBox ID="MobileTextBox" runat="server" Text='<%# Bind("Mobile") %>' />
</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>ليس هناك أي بيانات حاليا.</td>
</tr>
</table>
</EmptyDataTemplate>
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="إضافة" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="مسح" />
</td>
<td>
<asp:TextBox ID="EmpNameTextBox" runat="server" Text='<%# Bind("EmpName") %>' />
</td>
<td>
<asp:TextBox ID="UserNameTextBox" runat="server" Text='<%# Bind("UserName") %>' />
</td>
<td>
<asp:TextBox ID="passwordTextBox" runat="server" Text='<%# Bind("password") %>' />
</td>
<td>
<asp:TextBox ID="EmailTextBox" runat="server" Text='<%# Bind("Email") %>' />
</td>
<td>
<asp:TextBox ID="MobileTextBox" runat="server" Text='<%# Bind("Mobile") %>' />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr style="background-color: #EEE;color: black;">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="حذف" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="تعديل" />
</td>
<td>
<asp:Label ID="EmpNameLabel" runat="server" Text='<%# Eval("EmpName") %>' />
</td>
<td>
<asp:Label ID="UserNameLabel" runat="server" Text='<%# Eval("UserName") %>' />
</td>
<td>
<asp:Label ID="passwordLabel" runat="server" Text='<%# Eval("password") %>' />
</td>
<td>
<asp:Label ID="EmailLabel" runat="server" Text='<%# Eval("Email") %>' />
</td>
<td>
<asp:Label ID="MobileLabel" runat="server" Text='<%# Eval("Mobile") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server" style="direction: rtl; width: 100%">
<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; text-align: center; vertical-align: middle">
<tr runat="server" style="background-color: #5D7B9D;color: #FFF;">
<th runat="server" style="text-align: center"></th>
<th runat="server" style="text-align: center">الاسم</th>
<th runat="server" style="text-align: center">اسم المستخدم</th>
<th runat="server" style="text-align: center">كلمة المرور</th>
<th runat="server" style="text-align: center">الايميل</th>
<th runat="server" style="text-align: center">الجوال</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="text-align: center;background-color: #5D7B9D;font-family: Verdana, Arial, Helvetica, sans-serif;color: #FFFFFF">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr style="background-color: #E2DED6;font-weight: bold;color: #333333;">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="حذف" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="تعديل" />
</td>
<td>
<asp:Label ID="EmpNameLabel" runat="server" Text='<%# Eval("EmpName") %>' />
</td>
<td>
<asp:Label ID="UserNameLabel" runat="server" Text='<%# Eval("UserName") %>' />
</td>
<td>
<asp:Label ID="passwordLabel" runat="server" Text='<%# Eval("password") %>' />
</td>
<td>
<asp:Label ID="EmailLabel" runat="server" Text='<%# Eval("Email") %>' />
</td>
<td>
<asp:Label ID="MobileLabel" runat="server" Text='<%# Eval("Mobile") %>' />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
Sorry for the delay, but is the delete button not working? generally when you use the templates, it automatically sets it all up so when you click the delete button it runs the deletecommand. However, the Parameters you currently have
<InsertParameters>
<asp:Parameter Name="inm" />
<asp:Parameter Name="ius" />
<asp:Parameter Name="ips" />
<asp:Parameter Name="iem" />
<asp:Parameter Name="imob" />
</InsertParameters>
Don't seem to be really doing any thing, you need to add what they should be expecting. IE string, char, int... something along those lines.
The other part, is the command argument that you have added to your buttons. I don't think you need that.
Sorry if this is super late and you already figured it out.

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

ASP.net Forms/DropDownList Help

I have created 2 dropdownlists that are binded to a SQL DB and then pulling up a GridView. But, more specifically is there a way to have 3 user picked boxes and then have a Gridview show up? I would like to have a quick efficient way to do this without problems. I created the first 2 DDLs with autopostback and not working properly. any suggestions?
<asp:Label ID="CustomerNumberLabel" runat="server" Text="Customer Number " Width="125px"></asp:Label>
<asp:DropDownList ID="CustomerNumber" runat="server" AutoPostBack="True"
DataSourceID="ADDRDataSource" DataTextField="SACSNO"
DataValueField="SACSNO" AppendDataBoundItems="True">
<asp:ListItem Text="Select a Customer" Value="" Selected="True" />
</asp:DropDownList><br />
<asp:SqlDataSource ID="ADDRDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:iSeriesHistoryConnectionString %>"
SelectCommand="SELECT [SACSNO] FROM [ADDR] WHERE ([SARP#1] = #column1)">
<SelectParameters>
<asp:SessionParameter Name="column1" SessionField="userName" Type="Decimal" />
</SelectParameters>
</asp:SqlDataSource>
<asp:Label ID="ShipToNumberLabel" runat="server" Text="Ship-to Location " Width="125px"></asp:Label>
<asp:DropDownList ID="ShipToNumber" runat="server"
DataSourceID="ADDRShipToNumberDataSource" DataTextField="SASHNM"
DataValueField="SASHNM" AutoPostBack="True">
<asp:ListItem Text="Select Ship-To Location" Value="" Selected="True" />
</asp:DropDownList>
<asp:SqlDataSource ID="ADDRShipToNumberDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:iSeriesHistoryConnectionString %>"
SelectCommand="SELECT [SASHNM], [SASAD1], [SASAD2], [SASCTY], [SACSNO], [SASHST], [SASZIP] FROM [ADDR] WHERE ([SACSNO] = #SACSNO)">
<SelectParameters>
<asp:ControlParameter ControlID="CustomerNumber" Name="SACSNO"
PropertyName="SelectedValue" Type="Decimal" />
</SelectParameters>
</asp:SqlDataSource>
<br /><br />
<asp:FormView ID="FormView1" runat="server"
DataSourceID="ADDRShippingDataSource" Width="400px">
<EditItemTemplate>
SACSNO:
<asp:TextBox ID="SACSNOTextBox" runat="server" Text='<%# Bind("SACSNO") %>' />
<br />
SASHNM:
<asp:TextBox ID="SASHNMTextBox" runat="server" Text='<%# Bind("SASHNM") %>' />
<br />
SASAD1:
<asp:TextBox ID="SASAD1TextBox" runat="server" Text='<%# Bind("SASAD1") %>' />
<br />
SASAD2:
<asp:TextBox ID="SASAD2TextBox" runat="server" Text='<%# Bind("SASAD2") %>' />
<br />
SASCTY:
<asp:TextBox ID="SASCTYTextBox" runat="server" Text='<%# Bind("SASCTY") %>' />
<br />
SASHST:
<asp:TextBox ID="SASHSTTextBox" runat="server" Text='<%# Bind("SASHST") %>' />
<br />
SASZIP:
<asp:TextBox ID="SASZIPTextBox" runat="server" Text='<%# Bind("SASZIP") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
SACSNO:
<asp:TextBox ID="SACSNOTextBox" runat="server" Text='<%# Bind("SACSNO") %>' />
<br />
SASHNM:
<asp:TextBox ID="SASHNMTextBox" runat="server" Text='<%# Bind("SASHNM") %>' />
<br />
SASAD1:
<asp:TextBox ID="SASAD1TextBox" runat="server" Text='<%# Bind("SASAD1") %>' />
<br />
SASAD2:
<asp:TextBox ID="SASAD2TextBox" runat="server" Text='<%# Bind("SASAD2") %>' />
<br />
SASCTY:
<asp:TextBox ID="SASCTYTextBox" runat="server" Text='<%# Bind("SASCTY") %>' />
<br />
SASHST:
<asp:TextBox ID="SASHSTTextBox" runat="server" Text='<%# Bind("SASHST") %>' />
<br />
SASZIP:
<asp:TextBox ID="SASZIPTextBox" runat="server" Text='<%# Bind("SASZIP") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
Customer Detail<br />
<br />
<table class="style1" width="35px">
<tr>
<td class="style2" align="center" >
Address Line 1</td>
<td class="style3" align="center" >
<asp:Label ID="SASAD1Label" runat="server" Text='<%# Bind("SASAD1") %>' />
</td>
</tr>
<tr>
<td class="style2" align="center" >
Address Line 2</td>
<td class="style3" align="center" >
<asp:Label ID="SASAD2Label" runat="server" Text='<%# Bind("SASAD2") %>' />
</td>
</tr>
<tr>
<td class="style2" align="center">
City</td>
<td class="style3" align="center" >
<asp:Label ID="SASCTYLabel" runat="server" Text='<%# Bind("SASCTY") %>' />
</td>
</tr>
<tr>
<td align="center" class="style2">
State</td>
<td class="style3" align="center" >
<asp:Label ID="SASHSTLabel" runat="server" Text='<%# Bind("SASHST") %>' />
</td>
</tr>
<tr>
<td align="center" class="style2">
Zip</td>
<td class="style3" align="center" >
<asp:Label ID="SASZIPLabel" runat="server" Text='<%# Bind("SASZIP") %>' />
</td>
</tr>
</table>
<br />
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="ADDRShippingDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:iSeriesHistoryConnectionString %>"
SelectCommand="SELECT [SACSNO], [SASHNM], [SASAD1], [SASAD2], [SASCTY], [SASHST], [SASZIP] FROM [ADDR] WHERE ([SASHNM] = #SASHNM)">
<SelectParameters>
<asp:ControlParameter ControlID="ShipToNumber" Name="SASHNM"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
You can turn off AutoPostBack for all the DropDownLists, and add a Button called Lookup with something like the following in the Lookup Button_Click event:
ADDRShippingDataSource.SelectParameters.Clear()
If ShipToNumber.SelectedValue <> "" Then
ADDRShippingDataSource.SelectParameters.Add("SASHNM", ShipToNumber.SelectedValue)
End If
If CustomerNumber.SelectedValue <> "" Then
ADDRShippingDataSource.SelectParameters.Add("SACSNO", CustomerNumber.SelectedValue)
End If
ADDRShippingDataSource.DataBind()
Your select command would need to be updated to include the additional criteria in your DataSource:
SELECT [SACSNO], [SASHNM], [SASAD1], [SASAD2], [SASCTY], [SASHST], [SASZIP] FROM [ADDR] WHERE (#SASHNM IS NULL OR [SASHNM] = #SASHNM) OR (#SACSNO IS NULL OR [SACSNO] = #SACSNO)

Resources