How to generate checkbox for every field in database using GridView - asp.net

I have limited knowledge on VB coding. I am now creating a system which allow customer to select exhibition event and booth number they want and next reserved which day they want to rent.
By default, in GridView control can add checkbox Field but it only generate 1 checkbox for 1 row of data.
As state in the title, I have no idea how to generate the checkboxes for every field in database call D1,D2,D3,D4,D5,D6 and D7, each carry value 0 by default.
Now I want every single field have a checkbox to allow customer select which day they want to reserve and retrieve their checked value to stole into corresponding D1-D7 field, checked value will update value 0 to 1.
Next, how should I coding to store the checked value into database? in default.aspx or default.aspx.vb?
Or any other suggestion to generate checkbox instead of using gridview?
The default view using GridView
What I want
My coding:
<%# Page Language="VB" MasterPageFile="~/MasterPageMember.master" AutoEventWireup="false" CodeFile="member_view_event_list.aspx.vb" Inherits="member_view_event_list" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
.style8
{
width: 46px;
}
.style9
{
}
.style10
{
width: 86px;
}
</style>
</asp:Content>
<asp:Content ID="ContentPlaceHolder2" runat="server"
contentplaceholderid="ContentPlaceHolder2">
<table width="80%">
<tr><td class="style10"> </td><td class="style8"> </td><td> </td></tr>
<tr><td class="style10">
<asp:Label ID="Label1" runat="server" Text="Select Event:"></asp:Label>
</td><td class="style8">
<asp:DropDownList ID="ddlEventList" runat="server"
DataSourceID="SqlDataSourceEvent" DataTextField="eventTitle"
DataValueField="eventID" AutoPostBack="True" Width="200">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSourceEvent" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
SelectCommand="SELECT DISTINCT [eventTitle], [eventID] FROM [booth_eventinfo]">
</asp:SqlDataSource>
</td><td>
</td></tr>
<tr><td class="style10">
<asp:Label ID="Label2" runat="server" Text="Select Booth:"></asp:Label>
</td><td class="style8">
<asp:DropDownList ID="ddlBoothList" runat="server"
DataSourceID="SqlDataSourceBooth" DataTextField="boothAlias"
DataValueField="boothID" AutoPostBack="True" Width="200">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSourceBooth" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
SelectCommand="SELECT [boothAlias], [boothID] FROM [booth_eventinfo] WHERE ([eventID] = #eventID)">
<SelectParameters>
<asp:ControlParameter ControlID="ddlEventList" Name="eventID"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</td><td>
</td></tr>
<tr><td class="style10">
</td><td class="style8">
</td><td>
</td></tr>
<tr><td class="style9" colspan="3">
<asp:GridView ID="GridViewDay" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataSourceID="SqlDataSourceDay" ForeColor="#333333"
GridLines="None">
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<Columns>
<asp:BoundField DataField="D1" HeaderText="Day1" SortExpression="D1" />
<asp:BoundField DataField="D2" HeaderText="Day2" SortExpression="D2" />
<asp:BoundField DataField="D3" HeaderText="Day3" SortExpression="D3" />
<asp:BoundField DataField="D4" HeaderText="Day4" SortExpression="D4" />
<asp:BoundField DataField="D5" HeaderText="Day5" SortExpression="D5" />
<asp:BoundField DataField="D6" HeaderText="Day6" SortExpression="D6" />
<asp:BoundField DataField="D7" HeaderText="Day7" SortExpression="D7" />
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSourceDay" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
SelectCommand="SELECT [D1], [D7], [D6], [D5], [D4], [D3], [D2] FROM [booth_eventinfo] WHERE ([boothID] = #boothID)">
<SelectParameters>
<asp:ControlParameter ControlID="ddlBoothList" Name="boothID"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</td></tr>
<tr><td class="style10">
</td><td class="style8">
<asp:CheckBox ID="CheckBox1" runat="server" />
</td><td>
</td></tr>
</table>
</asp:Content>

You need to change your 'BoundField' to a 'TemplateField' for each CheckBox control you desire. The code example below shows you how to do this. Note the binding expression syntax for your DataField value:
<asp:TemplateField HeaderText="Day1" SortExpression="D1" HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("D1") %>' />
</ItemTemplate>
</asp:TemplateField>

This may help you out. Instead of using a grid view you can use a asp:CheckBoxList, if the requirement is to only place checkboxes for the seven days. Once the list is created, you can style it horizontally using css so that it adheres to the appearance as shown in the image. This link gives a preview of a checkboxlist.
For the second part of the question, you can save it in default.aspx.vb during the final submit.
In case you want to use a gridview, then you would have to add seven templated columns and bind it to the data source.

Related

connect grid view to database

I build a ASP.net project but I'm new in it ...
I got this problem :
got a textbox1 and button name = filter and grid view
there is database with too table (mark , Course )
I need when I write a sentence in textbox1 and press filter grid view connect to databse and take the data according to the textbox1 content
and by default bring every thing without filter
I make it but The grid view don't appear
there is no error
<table >
<tr>
<td colspan= "2" bgcolor="#4B6C9E" >
<font color = white> Choose The Course :</font>
</td>
</tr>
<tr>
<td> <asp:Label ID="Label1" runat="server" Text="Course :" ></asp:Label>
</td>
<td><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan = "2" align = "center">
<asp:Button ID="Button1" runat="server" Text="Filter" />
</td>
</tr>
</table>
<br />
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="StdID" HeaderText="StdID" SortExpression="StdID" />
<asp:BoundField DataField="Mark" HeaderText="Mark" SortExpression="Mark" />
<asp:BoundField DataField="CourseID" HeaderText="CourseID"
SortExpression="CourseID" />
<asp:BoundField DataField="StudentName" HeaderText="StudentName"
SortExpression="StudentName" />
<asp:BoundField DataField="CourseName" HeaderText="CourseName"
SortExpression="CourseName" />
<asp:BoundField DataField="Year" HeaderText="Year" SortExpression="Year" />
<asp:BoundField DataField="Semester" HeaderText="Semester"
SortExpression="Semester" />
<asp:BoundField DataField="Grade" HeaderText="Grade" SortExpression="Grade" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT Marks.StdID, Marks.Mark, Marks.CourseID, Marks.StudentName, Course.CourseName, Course.Year, Course.Semester, Course.Grade FROM Marks INNER JOIN Course ON Marks.CourseID = Course.ID WHERE (Course.CourseName LIKE '#name')">
<SelectParameters>
<asp:ControlParameter Name="name" ControlID="TextBox1" PropertyName="Text" DefaultValue="%" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
note: when I execute the query in database its worked perfect
please help as fast as you can
Gridiview doenst show anything if there is no row coming from the datasource.
This clause is wrong "WHERE (Course.CourseName LIKE '#name'", you don't need to put #name inside string, the database will search for a course named '#name', put the parameter directly inside the SQL.
This way:
SelectCommand="SELECT Marks.StdID, Marks.Mark, Marks.CourseID, Marks.StudentName, Course.CourseName, Course.Year, Course.Semester, Course.Grade FROM Marks INNER JOIN Course ON Marks.CourseID = Course.ID WHERE (Course.CourseName LIKE #name)"

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...

AjaxControlToolkit - GridView wont select - don't understand viewstate

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

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