AjaxControlToolkit - GridView wont select - don't understand viewstate - asp.net

Overview:
I have two text boxes at the top of this form for inputting a beginning/ending date.
In the middle of the form I have a gridview that is populated with rows based on those dates.
At the bottom of the form I have a report generated based on which row is selected in the grid.
I selected the BeginningDate and the EndingDate and the gridview becomes populated (working). When I click the "Select" button on a row in the grid something is happening that makes it break. The row isn't selected. I know this because the CSS thats usually applied (by default) to a selected row in the gridview is not applied.
Additionally in the code-behind I'm setting...
lblGridError.Text = gridJobsReport.SelectedIndex.ToString()
The page load even has the same code, so the label reads "-1" when the page loads but never changes when I click the select buttons on the gridview. Something is breaking my Async postbacks. I wish I understood viewstate better, I'm always suspicious of it being the culprit but honestly I have no idea.
<%# Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="BidReport.aspx.vb" Inherits="BidReport" %>
<%# Register assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<ajaxToolkit:ToolkitScriptManager ID="tsmgrJobsReport" runat="server"
CombineScripts="True">
</ajaxToolkit:ToolkitScriptManager>
<p>
Enter a date range to populate the Jobs Grid.</p>
<asp:UpdatePanel ID="uPanelForm" runat="server">
<ContentTemplate>
<table>
<tr>
<td style="text-align: right">
<asp:Label ID="lblBeginningDate" runat="server" Text="Beginning Date:"></asp:Label></td>
<td>
<asp:TextBox ID="txtBeginningDate" runat="server" AutoPostBack="True"
CausesValidation="True"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="txtBeginningDate_CalendarExtender"
runat="server"
TargetControlID="txtBeginningDate">
</ajaxToolkit:CalendarExtender>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvBeginningdate" runat="server"
ControlToValidate="txtBeginningDate"
ErrorMessage="You must enter the Beginning Date" Font-Bold="True"
ForeColor="Red">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revBeginningDate" runat="server"
ControlToValidate="txtBeginningDate"
ErrorMessage="Posted Date must be in the format "DD/MM/YYYY""
Font-Bold="True" ForeColor="Red"
ValidationExpression="^([1-9]|1[012])/([1-9]|[12][0-9]|3[01])/(20\d\d)$">*</asp:RegularExpressionValidator>
</td>
<td rowspan="2">
<asp:CompareValidator ID="cvBeginDateLTEndDate" runat="server"
ControlToCompare="txtEndingDate" ControlToValidate="txtBeginningDate"
ErrorMessage="Beginning Date must be earlier than the Ending Date."
Font-Bold="True" ForeColor="Red" Operator="LessThan">*</asp:CompareValidator>
</td>
</tr>
<tr>
<td style="text-align: right">
<asp:Label ID="lblEndingDate" runat="server" Text="Ending Date:"></asp:Label></td>
<td>
<asp:TextBox ID="txtEndingDate" runat="server" AutoPostBack="True"
CausesValidation="True"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="txtEndingDate_CalendarExtender"
runat="server" TargetControlID="txtEndingDate">
</ajaxToolkit:CalendarExtender>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvEndingDate" runat="server"
ControlToValidate="txtEndingDate"
ErrorMessage="You must enter the EndingDate Date" Font-Bold="True"
ForeColor="Red">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revEndingDate" runat="server"
ControlToValidate="txtEndingDate"
ErrorMessage="Posted Date must be in the format "DD/MM/YYYY""
Font-Bold="True" ForeColor="Red"
ValidationExpression="^([1-9]|1[012])/([1-9]|[12][0-9]|3[01])/(20\d\d)$">*</asp:RegularExpressionValidator>
</td>
</tr>
</table>
<asp:ValidationSummary ID="valsumDates" runat="server" ForeColor="Red" />
<p>Click or Tap the "SELECT" button in the right column next to the Job you want and
a report will be generated below.</p>
<asp:GridView ID="gridJobsReport" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataKeyNames="PostingID" DataSourceID="sqlDSReportGrid"
ForeColor="#333333" GridLines="Horizontal"
ShowHeaderWhenEmpty="True" Width="100%">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="PostingID" HeaderText="PostingID" ReadOnly="True"
SortExpression="PostingID" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Department" HeaderText="Department"
SortExpression="Department" />
<asp:BoundField DataField="JobName" HeaderText="JobName"
SortExpression="JobName" />
<asp:BoundField DataField="Shift" HeaderText="Shift" SortExpression="Shift" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Needs" HeaderText="Needs"
SortExpression="Needs" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="PostedDate" HeaderText="PostedDate"
SortExpression="PostedDate" DataFormatString="{0:d}" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="PostedTime" HeaderText="Time"
SortExpression="PostedTime" DataFormatString="{0:t}" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="ClosingDate" HeaderText="ClosingDate"
SortExpression="ClosingDate" DataFormatString="{0:d}" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="ClosingTime" HeaderText="Time"
SortExpression="ClosingTime" DataFormatString="{0:t}" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:CommandField ButtonType="Button" CausesValidation="True"
ShowSelectButton="true" />
</Columns>
<EditRowStyle BackColor="#999999" />
<EmptyDataRowStyle HorizontalAlign="Center" />
<EmptyDataTemplate>
There is currently no data to display based on the date range provided.
</EmptyDataTemplate>
<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>
<br />
<asp:Label ID="lblGridError" runat="server"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<ajaxToolkit:UpdatePanelAnimationExtender ID="uPanelForm_UpdatePanelAnimationExtender"
runat="server" TargetControlID="uPanelForm">
</ajaxToolkit:UpdatePanelAnimationExtender>
<p>You can print or save the report using the buttons at the top of the report.</p>
<asp:UpdatePanel ID="uPanelJobsReport" runat="server">
<ContentTemplate>
<rsweb:ReportViewer ID="rvJobsReport" runat="server" Width="100%">
</rsweb:ReportViewer>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="gridJobsReport"
EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
<asp:SqlDataSource ID="sqlDSReportGrid" runat="server"
ConnectionString="<%$ ConnectionStrings:JobsDB %>"
SelectCommand="SELECT dbo.tblJobPostings.PostingID, dbo.tblDepartments.Department, dbo.tblJobs.JobName,
dbo.tblJobPostings.Shift, dbo.tblJobPostings.Needs, dbo.tblJobPostings.PostedDate,
dbo.tblJobPostings.PostedTime, dbo.tblJobPostings.ClosingDate, dbo.tblJobPostings.ClosingTime
FROM dbo.tblJobPostings
INNER JOIN dbo.tblJobs ON dbo.tblJobPostings.JobID = dbo.tblJobs.JobID
INNER JOIN dbo.tblDepartments ON dbo.tblJobPostings.DeptID = dbo.tblDepartments.DeptID
WHERE dbo.tblJobPostings.ClosingDate >= #BeginningDate
AND dbo.tblJobPostings.ClosingDate <= #EndingDate
ORDER BY dbo.tblJobPostings.ClosingDate Asc">
<SelectParameters>
<asp:ControlParameter ControlID="txtBeginningDate" Name="BeginningDate"
PropertyName="Text" ConvertEmptyStringToNull="False" DefaultValue="" />
<asp:ControlParameter ControlID="txtEndingDate" Name="EndingDate"
PropertyName="Text" ConvertEmptyStringToNull="False" DefaultValue="" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="sqlDSJobReport" runat="server"></asp:SqlDataSource>
</asp:Content>

I really don't understand why this worked, but I decided to try handling the dates manually with session variables and its working perfectly now. It doesn't matter if I mess with the session state on the update panels or any of the form elements it seems to work no matter what now.
I guess that after the initial asyncpostback the sqldatasource wasn't reading the values in the textboxes, or something. If anyone can explain what was going on in another "Answer Question" section I'll accept it.
If Page.IsPostBack Then
Session("sBeginningDate") = txtBeginningDate.Text
Sessoin("sEndingDate") = txtEndingDate.Text
txtBeginningDate.Text = Session("sBeginningdate")
txtEndingDate.Text = Session("sEndingDate")
Else
Session("sBeginningDate") = Now().AddDays(-14)
Session("sEndingDate") = Now()
txtBeginningDate.Text = Session("sBeginningDate").ToShortDateString
txtEndingDate.Text = Session("sEndingDate").ToShortDateString
End If

Related

using dropdown list value in a URL

I have a page that the user chooses a date range, a name, and a Form type (A, B, E, T). On the basis of that, I populate a grid with the results and hyperlink a report number. When the user clicks the report number, a report is displayed. How can I insert the drop down list selected value into the URL to get the proper report based upon the report type the user chooses? If the user chooses Form A, the URL for SSRS should call the forma report from SSRS, and so on.
Markup
<body>
<link href="StyleSheet.css" rel="stylesheet" />
<form id="form1" runat="server">
<div>
<center><h1>Custom Reporting<br />
Pick a date range, an Inspector, and the type of inspection to list:</h1>
<p>Note - Date range is the dates of inspection, not dates of data input</p><br />
Start date: <asp:TextBox ID="stdt" runat="server"></asp:TextBox><asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="stdt" ErrorMessage="mm/dd/yyyy" ValidationExpression="^((0?[13578]|10|12)(-|\/)(([1-9])|(0[1-9])|([12])([0-9]?)|(3[01]?))(-|\/)((19)([2-9])(\d{1})|(20)([01])(\d{1})|([8901])(\d{1}))|(0?[2469]|11)(-|\/)(([1-9])|(0[1-9])|([12])([0-9]?)|(3[0]?))(-|\/)((19)([2-9])(\d{1})|(20)([01])(\d{1})|([8901])(\d{1})))$" Display="Dynamic"></asp:RegularExpressionValidator> End date: <asp:TextBox ID="enddt" runat="server">
</asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="enddt" ErrorMessage="mm/dd/yyyy" ValidationExpression="^((0?[13578]|10|12)(-|\/)(([1-9])|(0[1-9])|([12])([0-9]?)|(3[01]?))(-|\/)((19)([2-9])(\d{1})|(20)([01])(\d{1})|([8901])(\d{1}))|(0?[2469]|11)(-|\/)(([1-9])|(0[1-9])|([12])([0-9]?)|(3[0]?))(-|\/)((19)([2-9])(\d{1})|(20)([01])(\d{1})|([8901])(\d{1})))$" Display="Dynamic"></asp:RegularExpressionValidator> Inspector: <asp:DropDownList ID="DDLInsp" runat="server" DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField="Name">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ESDFormsConnectionString %>" SelectCommand="SELECT [Name] FROM [Inspectors] ORDER BY [Name]"></asp:SqlDataSource>
Inspection Type: <asp:DropDownList ID="DDLType" runat="server">
<asp:ListItem>Form A</asp:ListItem>
<asp:ListItem>Form B</asp:ListItem>
<asp:ListItem>Form E</asp:ListItem>
<asp:ListItem>Form T</asp:ListItem>
<asp:ListItem Selected="True">Pick One</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:Button ID="btnFind" runat="server" Text="Find Reports" />
<br />
</center>
</div>
<br />
<center>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" EmptyDataText="No records found" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical">
<AlternatingRowStyle BackColor="#DCDCDC" />
<Columns>
<asp:BoundField DataField="enddt" HeaderText ="Date" DataFormatString="{0:d}" />
<asp:HyperlinkField HeaderText="Report Number" DataTextField="rptnum" DataNavigateURLFields="rptnum" DataNavigateurlformatstring="http://servername/ReportServer?/esdforms/THE REPORT TITLE SHOULD GO HERE&rs:Command=Render&rc:Parameters=False&rptnum={0}" />
</Columns>
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#0000A9" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#000065" />
</asp:GridView></center>
</form>

Need a Gridview to Change when DropDownList changes

I have a dropdownlist in ASP.Net (I am using VB.Net) and my ASP.Net code follows. What I would like to do is have that Girdview populate dynamically off of the DropDownList. If the first option (showing nothing) is chosen, I would like everything possible in the Gridview to show. If one of the other options is chosen, I would like the GridView to filter based on that option. I can see the DropDownList, but nothing shows up in the Gridview. I imagine the issue has to do with binding the DropDownList to the Gridview somehow.
Thanks in advance.
<%# Page Title="Home Page" Language="VB" AutoEventWireup="true" CodeBehind="Default.aspx.vb" Inherits="SAP._Default" %>
<%# Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Tab Container Tips & Tricks</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</cc1:ToolkitScriptManager>
<cc1:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0">
<cc1:TabPanel ID="TabPanel1" runat="server" HeaderText="Screening">
<ContentTemplate>
<asp:Label ID="Label2" runat="server" Text="Pull For Screening "></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server"><asp:ListItem>10</asp:ListItem>
<asp:ListItem>20</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Add Applicants" />
<asp:Label ID="Label3" runat="server" Text="Choose Campus: "></asp:Label>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True">
<asp:ListItem></asp:ListItem>
<asp:ListItem Text="All" Value="%"></asp:ListItem>
<asp:ListItem>RC</asp:ListItem>
<asp:ListItem>HS</asp:ListItem>
<asp:ListItem>TL</asp:ListItem>
<asp:ListItem>PH</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ScreenerView %>" ProviderName="<%$ ConnectionStrings:ScreenerView.ProviderName %>"
SelectCommand="SELECT [ScreenerID], [LEGAL_FNAME], [LEGAL_LNAME], [APPL_PERSON_ID], [AAMC_ID], [GENDER], [URM], [RecMCAT], [SciGPA], [LEGAL_RES_STATE_CD], [PullDate], [First] FROM [vw_Screener]"
FilterExpression="Screener ID LIKE '?' AND First LIKE '?'">
<SelectParameters>
<asp:Parameter Name="intS" />
</SelectParameters>
<FilterParameters>
<asp:ControlParameter ControlID="DropDownList2" PropertyName="SelectedValue" />
</FilterParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" CellPadding="4" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="ScreenerID" HeaderText="ScreenerID" SortExpression="ScreenerID" Visible="False"></asp:BoundField>
<asp:BoundField DataField="LEGAL_FNAME" HeaderText="First Name" SortExpression="LEGAL_FNAME" />
<asp:BoundField DataField="LEGAL_LNAME" HeaderText="Last Name" SortExpression="LEGAL_LNAME" />
<asp:BoundField DataField="APPL_PERSON_ID" HeaderText="APPL_PERSON_ID" SortExpression="APPL_PERSON_ID" Visible="False" />
<asp:BoundField DataField="AAMC_ID" HeaderText="AAMC" SortExpression="AAMC_ID" />
<asp:BoundField DataField="GENDER" HeaderText="Gender" SortExpression="GENDER" />
<asp:BoundField DataField="URM" HeaderText="URM" SortExpression="URM" />
<asp:BoundField DataField="RecMCAT" HeaderText="MCAT" SortExpression="RecMCAT" />
<asp:BoundField DataField="SciGPA" HeaderText="Sci. GPA" SortExpression="SciGPA" />
<asp:BoundField DataField="LEGAL_RES_STATE_CD" HeaderText="State" SortExpression="LEGAL_RES_STATE_CD" />
<asp:BoundField DataField="PullDate" HeaderText="Date Pulled" DataFormatString = "{0:d}" SortExpression="PullDate" />
<asp:BoundField DataField="First" HeaderText="First Choice CC" SortExpression="First" />
</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>
</ContentTemplate>
</cc1:TabPanel>
You need to fix your FilterExpression and FilterParements in your SQLDataSource:
In your ASPX File you need to make the following changes:
FilterParameters: The items in this list will be used by the FilterExpression. If this is emtpy then your FilterExpression will have nothing to work with. However, you have ONE item in there, now you must link it to the FilterExpression with its index. Since you have ONE item then its index will be 0 (see filterexpression below). I assume its the [ScreenerID] so its probably an Int32? Then you need to specify that and set a defaultvalue:
<FilterParameters>
<asp:ControlParameter Name="ScreenerID" ControlID="DropDownList2"
PropertyName="SelectedValue" Type="Int32" DefaultValue="" />
</FilterParameters>
FilterExpression: The way you have it now is not correct because it is NOT linked with any real value say User-Interace (Dropdown) . You must link it based on its index/position in the FilterParameter items. Like we said above, since ScreenerID is the first item then it has index 0:
FilterExpression="ScreenerID = {0}"
DropDownList2: Since you already have AutoPostBack="True" you just need add event OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged"
If ScreenID is an integer, you need to remove the % from the value field in the ALL item like so: <asp:ListItem Value="" Text="ALL>
VB.NET Code-Behind: In your DropDownList2_SelectedIndexChanged event dont put any code in it. Like so:
Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged
'Leave empty
End Sub
Let me know if this is not working for you, I can update this answer as I find out more from you.

asp.net Can a GridView have two DataSources?

Afternoon All,
I have a gridview that i am using to display a list of 'Actions' from a database.
I have a dropdown list that is connected to this gridview, this enables a user to filter the data via the 'Action Status' in the dropdown list ('Assigned', 'Inprogress' & 'Completed'). This works perfectly fine....
What i am trying to do is have another filter option available for the user, they would like to also filter by user name. I have the datasource and the dropdown list set up for this but i can only have one datasource connected to my gridview?
Does anyone have a suggestionon how to enable the users to also filter by username as well as 'action status'?
Here is my code if you need to take a peek....
<asp:SqlDataSource ID="dsActions" runat="server"
ConnectionString="<%$ ConnectionStrings:SMCConnectionString %>"
SelectCommand="Populate_grdAllActions_Filter"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="ddFilterStatus" Name="ActionStatusID"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="dsActionsByUser" runat="server"
ConnectionString="<%$ ConnectionStrings:SMCConnectionString %>"
SelectCommand="Populate_grdAllActions_Filter_By_User"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="ddFilterUsers" Name="UserID"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="dsFilterList" runat="server"
ConnectionString="<%$ ConnectionStrings:SMCConnectionString %>"
SelectCommand="SELECT * FROM [ActionStatus]"></asp:SqlDataSource>
<asp:SqlDataSource ID="dsFilterUsers" runat="server"
ConnectionString="<%$ ConnectionStrings:SMCConnectionString %>"
SelectCommand="SELECT * FROM [UserSimpleList]"></asp:SqlDataSource>
<table style="width: 400px">
<tr>
<td colspan="2" style="height: 25px"><b>Filter Options:</b></td>
</tr>
<tr>
<td style="width: 158px">
Select Action Status:</td>
<td>
<asp:DropDownList ID="ddFilterStatus" runat="server"
DataTextField="ActionStatus" DataValueField="ActionStatusID"
AutoPostBack="True" DataSourceID="dsFilterList"></asp:DropDownList>
</td>
</tr>
<tr>
<td style="width: 158px">
Select Actions by User:</td>
<td>
<asp:DropDownList ID="ddFilterUsers" runat="server"
DataTextField="UserFullName" DataValueField="UserID"
AutoPostBack="True" DataSourceID="dsFilterUsers"></asp:DropDownList></td>
</tr>
</table>
<br/>
<asp:GridView ID="grdActions" runat="server" AutoGenerateColumns="False"
DataSourceID="dsActions" CssClass="mGrid"
PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt"
AllowPaging="True" PageSize="6" DataKeyNames="ActionID" Width="68%" >
<AlternatingRowStyle CssClass="alt" />
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="ActionID" DataNavigateUrlFormatString="~/UpdateAction.aspx?Edit={0}"
DataTextField="ActionID" HeaderText="Action ID" >
<HeaderStyle HorizontalAlign="Center" Wrap="True" />
<ItemStyle HorizontalAlign="Center" />
</asp:HyperLinkField>
<asp:BoundField DataField="Action" HeaderText="Action"
SortExpression="Action" >
<HeaderStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Owner" HeaderText="Owner"
SortExpression="Owner">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="TargetDate" HeaderText="Target Date"
SortExpression="TargetDate" DataFormatString="{0:dd-MM-yyyy} " >
<HeaderStyle HorizontalAlign="Center" Wrap="True" />
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="Action Status" HeaderText="Action Status"
SortExpression="Action Status" >
<HeaderStyle HorizontalAlign="Center" Wrap="True" />
<ItemStyle Wrap="False" />
</asp:BoundField>
</Columns>
<PagerStyle CssClass="pgr" />
</asp:GridView>
Any help is much appriechiated in advance.
Regards
Betty
You can determine which option the user selected, then set the Datasource in code-behind rather than wired them up in the aspx.
Pseudocode assumes that if the FilterUsers dropdown was selected, then bind to the Action By User data source:
if(IsPostBack){
if(ddlFilterUsers.SelectedValue <> ""){
grdActions.DataSource = dsActionsByUser;
dsFilterUsers.DataBind();
//etc
}
}
In the code behind part, On ddFilterStatus_SelectIndexChanged() Event, Check for appropriate "Action Status" and Select the Data source as follows,
if(ddFilterStatus.SelectedValue == someid1)
{
grdActions.DataSource = appropriate datasource
}
else
{
grdActions.DataSource = appropriate datasource
}
grdActions.DataBind()
Hope this helps...

DomEvent. AddHandler

I am facing little issue in my web application in asp.net.
i am receiving the below error :
Error: Sys.InvalidOperationException: Handler was not added through the Sys.UI.DomEvent.addHandler method.
I have used Updatepanel and this error occurs when i try to do some 2-3 actions very quickly.
and when next time i try to do take some action my web application just hungs up.
Please suggest.
Thanks
In my case this was caused by having the 'Close' control within an Update Panel in the Modal Popup. I fixed it by creating a 'dummy' button outside of the Update Panel, and setting it as the 'CancelControlID' in the MPE attributes:
<asp:Button ID="btnDummyCloseWindow" runat="server" Style="visibility: hidden"/>
<ajaxToolkit:ModalPopupExtender ID="mpeWindow" runat="server" PopupControlID="pnlWindow"
TargetControlID="btnDummyOtherButton" BackgroundCssClass="modalBackground"
DropShadow="false" CancelControlID="btnDummyCloseWindow" />
You'll need to make sure the close button that is present within your Update Panel has actions assigned to it to close the window (e.g. mpeWindow.hide()).
It's also worth noting that I was also making use of the TargetControlID 'fix' too, where a dummy button is referenced, so ignore the TargetControlID attribute there.
I've solved the problem setting ScriptMode property of ScriptManager to Release instead of Debug
By default ScriptManager is set to Debug mode.
I had the same problem and solved by placing the ModalPopupExtender or the user control that uses ModalPopupExtender inside an update panel.
Which ever way you want to look at it, the problem is inherit in what I believe is a bug in AJAX.
The only way I was able to resolve this was to control your Sorting or Paging on the server side where you control or more specifically refresh the UpdatePanel along with making sure the ModalPopup has been kept visible!
The reason for the error is really because once you do a sort of page change on a GridView that's inside an UpdatePanel, the controls have been "lost" to the UpdatePanel.
A better explanation is here.
Here is a column from my GridView...
<asp:GridView ID="gvTETstudents" runat="server" AutoGenerateColumns="False" AllowSorting="True" CellPadding="4" ForeColor="#333333" Font-Size="Small" Width="100%"
DataSourceID="sdsTETstudents"
OnRowCreated="gvTETstudents_RowCreated"
OnRowDataBound="gvTETstudents_RowDataBound"
OnDataBound="gvTETstudents_DataBound">
<Columns>
..
..
<ItemTemplate>
<asp:UpdatePanel ID="upWEF1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnWEFCLOSE" />
</Triggers>
<ContentTemplate>
...
...
<asp:Panel ID="pnlWEF2" runat="server" style="display:none;">
<table><tr><td>
<asp:Button ID="btnWEFshow" runat="server"
Text="ALL"
Font-Size="Small" Font-Names="Arial"
ToolTip="Click here to see all of this student's work experience feedback on file" />
<ajaxToolkit:ModalPopupExtender ID="mpeWEF" runat="server"
BackgroundCssClass="modalBackground"
OkControlID="btnWEFCLOSE"
PopupControlID="upWEF2"
TargetControlID="btnWEFshow">
</ajaxToolkit:ModalPopupExtender>
<asp:UpdatePanel ID="upWEF2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="pnlWEF3" runat="server" CssClass="pnlEndorsed">
<div id="Hdr" style="text-align: center">
<asp:Label ID="lblWEFHdr" runat="server">** CONTACT LOG **</asp:Label>
</div>
<div id="Bdy">
<table style="width:100%"><tr><td>
<asp:GridView ID="gvWEFContactLog" runat="server"
Font-Size="X-Small" CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="true" PageSize="8" AllowSorting="True" AutoGenerateColumns="False" Width="100%"
DataKeyNames="StudentContactLogID,Private,ApprenticeContactLogID"
DataSourceID="sdsWEF"
OnRowDataBound="gvWEFContactLog_RowDataBound"
OnPageIndexChanging="gvWEFContactLog_PageIndexChanging"
OnSorted="gvWEFContactLog_Sorted">
<Columns>
<asp:TemplateField HeaderText="First Entered" SortExpression="FirstEntered">
<ItemTemplate>
<asp:HiddenField ID="hfWEFStudCLid" runat="server" Value='<%# Eval("StudentContactLogID") %>' />
<asp:HiddenField ID="hfWEFAppCLid" runat="server" Value='<%# Eval("ApprenticeContactLogID") %>' />
<asp:HiddenField ID="hfPrivate" runat="server" Value='<%# Eval("Private") %>' />
<asp:HiddenField ID="hfNotes" runat="server" Value='<%# Eval("ContactNotes") %>' />
<asp:LinkButton ID="lnkWEFCLOG" runat="server"
Text='<%# Eval("FirstEntered","{0:d MMM yyyy HH:mm}") %>'></asp:LinkButton>
<a id="lnkDummy" runat="server" visible=false></a>
<ajaxToolkit:ModalPopupExtender ID="mpeWEFCLOG" runat="server"
OkControlID="btnWEFCLOSEview"
PopupControlID="upWEFCLOG"
TargetControlID="lnkWEFCLOG">
</ajaxToolkit:ModalPopupExtender>
<asp:UpdatePanel ID="upWEFCLOG" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div id="pnlWEFCLOG" runat="server" class="pnlCLOG">
<asp:TextBox ID="txtWEFCLOG" runat="server"
Wrap="true"
TextMode="MultiLine"
Rows="10"
ReadOnly="true"
Width="98%">
</asp:TextBox>
<br />
<asp:Button ID="btnWEFCLOSEview" runat="server" Text="OK" Width="100%" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Subject" HeaderText="Subject" SortExpression="Subject" />
<asp:BoundField Visible="False" DataField="StudentContactLogID" HeaderText="LogID"
InsertVisible="False" ReadOnly="True" SortExpression="StudentContactLogID">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="StaffName" HeaderText="Staff" ReadOnly="True" SortExpression="StaffName" />
<asp:TemplateField HeaderText="Contact Date Time" SortExpression="ContactDateTime">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ContactDateTime","{0:d MMM yyyy HH:mm}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Follow-Up Date" SortExpression="FollowUpDate">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("FollowUpDate","{0:d MMM yyyy}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Private" HeaderText="Private" SortExpression="Private" />
</Columns>
<EmptyDataTemplate>
No Current Entries
</EmptyDataTemplate>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
<asp:SqlDataSource ID="sdsWEF" runat="server" ConnectionString="<%$ ConnectionStrings:ATCNTV1ConnectionString %>"
SelectCommand="spTETStudentContactLogView" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Name="StudentID" Type="string" />
<asp:Parameter Name="WEF" Type="string" DefaultValue="%" />
</SelectParameters>
</asp:SqlDataSource>
</td></tr>
<tr style="text-align: center">
<td style="text-align: left">
<asp:Button ID="btnWEFCLOSE" runat="server"
Text="CLOSE"
CausesValidation="false" Font-Bold="True" Width="61px" />
</td>
</tr>
</table>
</div>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</td></tr></table>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
The major point of the code above is that I have a very deep GridView inside an UpdatePanel that's inside a ModalPopUp.
Now look at what I have inside that GridView:
OnPageIndexChanging
and
OnSorted
Inside the GridView, there is another ModalPopup and TextBox. Ignore that. That's only so the user can see the comments from the student's contact log as another popup window.
So if we now go to the code behind for the above two events:
protected void gvWEFContactLog_Sorted(object sender, EventArgs e)
{
GridView gvWEFCL = (GridView)sender;
GridViewRow gvRow = (GridViewRow)gvWEFCL.NamingContainer;
UpdatePanel upWEF1 = (UpdatePanel)gvRow.FindControl("upWEF1");
if (upWEF1 != null) upWEF1.Update();
AjaxControlToolkit.ModalPopupExtender mpeWEF = (AjaxControlToolkit.ModalPopupExtender)gvRow.FindControl("mpeWEF");
if (mpeWEF != null) mpeWEF.Show();
}
protected void gvWEFContactLog_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView gvWEFCL = (GridView)sender;
GridViewRow gvRow = (GridViewRow)gvWEFCL.NamingContainer;
UpdatePanel upWEF1 = (UpdatePanel)gvRow.FindControl("upWEF1");
if (upWEF1 != null) upWEF1.Update();
AjaxControlToolkit.ModalPopupExtender mpeWEF = (AjaxControlToolkit.ModalPopupExtender)gvRow.FindControl("mpeWEF");
if (mpeWEF != null) mpeWEF.Show();
}
Notice that I am not actually controlling the sorting or the paging itself. I am only forcing the GridView to call upon the main UpdatePanel (upWEF1) to refresh itself via an Update() call. The next step is to grab the ModalPopup I want to keep visible and re-Show() it!
And that's all there is to it!
I am sure there is a cleaner solution using JavaScript itself, but for me this avoids that dread meaningless error and I have a clean set of popups and update panels that can handle both hotlinks, sorting and paging as I want the GridView to perform!

ASP.Net SQLDataSource Filter - Input string was not in a correct format

I have a ASP.Net web page with a grid view. I want to filter the grid view data based on the selection of a drop down list. I have this working fine on another page. The difference on the problem page is that the column I need to filter against is an int rather than a varchar. When I load the page I get the error message: Input string was not in a correct format.
I have pasted code for the dropdownlist and datasource below. This must be a common requirement so I guess I'm missing something obvious...? On attempting to find a resolution via Google, other have the same problem. A post on very similar lines can be found at http://www.velocityreviews.com/forums/t123088-problem-in-filterparameters.html, unfortunately Gavin's resolution didn't work for me.
Many thanks,
Rob.
<%# Page Language="C#" MasterPageFile="~/Main.master" AutoEventWireup="true" CodeFile="BacheAccountSettings.aspx.cs"
Inherits="RDM.BacheTradeLoad" Title="Untitled Page" %>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<tr>
<td style="width: 100px;">
Filter:
</td>
<td style="width: 170px;">
<asp:DropDownList ID="ddlAccountSourceId" DataSourceID="dsAccountSourceId" AutoPostBack="true"
DataValueField="AccountId" runat="server" Width="130px" Font-Size="11px" AppendDataBoundItems="true">
<asp:ListItem Text="All" Value="%"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td colspan="1">
<asp:GridView ID="grdRefBacheAccount" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#E7E7FF" BorderWidth="1px" CellPadding="3" DataSourceID="dsArcReference"
GridLines="Horizontal" BorderStyle="None" EnableModelValidation="True" Style="position: static"
OnRowDataBound="grdRefBacheAccount_RowDataBound" AllowPaging="True" PageSize="25"
CssClass="Grid" AllowSorting="True">
<Columns>
<asp:CommandField ShowEditButton="True" ShowCancelButton="False" />
<asp:BoundField DataField="SourceID" HeaderText="SourceID" SortExpression="SourceID" />
<asp:BoundField DataField="GroupCompany" HeaderText="GroupCompany" SortExpression="GroupCompany" />
<asp:BoundField DataField="Portfolio" HeaderText="Portfolio" SortExpression="Portfolio" />
<asp:BoundField DataField="OnBehalfComp" HeaderText="OnBehalfComp" SortExpression="OnBehalfComp" />
<asp:BoundField DataField="AssignedTrader" HeaderText="AssignedTrader" SortExpression="AssignedTrader" />
</Columns>
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<SelectedRowStyle BackColor="#738A9C" ForeColor="#F7F7F7" Font-Bold="True" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<AlternatingRowStyle BackColor="#F7F7F7" />
</asp:GridView>
</td>
</tr>
<div id="divImportButton" align="right">
<asp:Button ID="btnImport" runat="server" Text="Import Trade" OnClick="btnImport_Click"
CssClass="Button" />
</div>
<asp:SqlDataSource ID="dsArcReference" runat="server" ConnectionString="<%$ ConnectionStrings:ARC_REFERENCEConnectionString %>"
SelectCommand="select ACCOUNT_SOURCE_ID as 'AccountId',
[ACCOUNT_BTF_GROUP_COMPANY] as 'GroupCompany',
[ACCOUNT_BTF_PORTFOLIO] as 'Portfolio',
[ACCOUNT_BTF_ON_BEHALF_COMPANY] as 'OnBehalfComp',
[ACCOUNT_BTF_ASSIGNED_TRADER] as 'AssignedTrader'
from dbo.REF_BACHE_ACCOUNT" UpdateCommand="update dbo.REF_BACHE_ACCOUNT
set [ACCOUNT_BTF_GROUP_COMPANY] = #GroupCompany,
[ACCOUNT_BTF_PORTFOLIO] = #Portfolio,
[ACCOUNT_BTF_ON_BEHALF_COMPANY] = #OnBehalfComp,
[ACCOUNT_BTF_ASSIGNED_TRADER] = #AssignedTrader
where [ACCOUNT_SOURCE_ID]=#SourceID" FilterExpression="SourceID={0}">
<FilterParameters>
<asp:ControlParameter Type="Int32" ControlID="ddlAccountSourceId" PropertyName="SelectedValue" />
</FilterParameters>
<UpdateParameters>
<asp:Parameter />
<asp:Parameter Name="ACCOUNT_SOURCE_ID" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="dsAccountSourceId" runat="server" ConnectionString="<%$ ConnectionStrings:ARC_REFERENCEConnectionString %>"
SelectCommand="SELECT DISTINCT [ACCOUNT_SOURCE_ID] as AccountId FROM [REF_BACHE_ACCOUNT]"
DataSourceMode="DataSet"></asp:SqlDataSource>
You pass a value that is not Int32.
<asp:ListItem Text="All" Value="%"></asp:ListItem>
Remove this line and its going to work. For show them all you need to find an other way...

Resources