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)"
Related
I have a simple GridView (with an ID of 'GridViewAttribs') which displays some values from a database.
Within my GridViewAttribs I wish to have a (nested?) ListView but for some reason I cannot use the asp:ControlParameter ControlID="GridViewAttribs" PropertyName as no results are returned in my (nested) ListView.
If I do NOT use the ControlParameter and hardcode my SELECT statement for the ListView, everything works as expected.
Here's my code:
<asp:SqlDataSource ID="SqlDataSourceAttribHeadings" runat="server"
ConnectionString="<%$ ConnectionStrings:customer_support_devConnectionString %>"
ProviderName="<%$ ConnectionStrings:customer_support_devConnectionString.ProviderName %>"
SelectCommand="SELECT equipment_attrib_heading_id, equipment_model_id, equipment_attrib_name FROM equipment_new_attrib_headings WHERE (equipment_model_id = #equipment_model_id) AND (equipment_attrib_heading_deleted = 0) ORDER BY equipment_attrib_name">
<SelectParameters>
<asp:SessionParameter DefaultValue="" Name="equipment_model_id"
SessionField="EquipmentModelID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridViewAttribs" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataKeyNames="equipment_attrib_heading_id"
DataSourceID="SqlDataSourceAttribHeadings" ForeColor="#333333" GridLines="None"
style="margin-right: 0px">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="equipment_attrib_heading_id"
HeaderText="equipment_attrib_heading_id" ReadOnly="True"
SortExpression="equipment_attrib_heading_id" />
<asp:BoundField DataField="equipment_model_id" HeaderText="equipment_model_id"
SortExpression="equipment_model_id" />
<asp:BoundField DataField="equipment_attrib_name"
HeaderText="equipment_attrib_name" SortExpression="equipment_attrib_name" />
<asp:TemplateField HeaderText="equipment_attrib_value_details" SortExpression="equipment_attrib_value_details">
<ItemTemplate>
<asp:SqlDataSource ID="SqlDataSourceAttribValues" runat="server"
ConnectionString="<%$ ConnectionStrings:customer_support_devConnectionString %>"
ProviderName="<%$ ConnectionStrings:customer_support_devConnectionString.ProviderName %>"
SelectCommand="SELECT [equipment_attrib_value_details] FROM [equipment_new_attrib_values] WHERE (equipment_attrib_heading_id = #head_id) AND (equipment_id = #equipment_id) AND (equipment_attrib_value_deleted = 0)">
<SelectParameters>
<asp:QueryStringParameter Name="equipment_id" QueryStringField="id"
Type="Int32" />
<asp:ControlParameter ControlID="GridViewAttribs"
Name="head_id" PropertyName="SelectedDataKey.Values[equipment_attrib_heading_id]" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:ListView ID="ListViewAttribValues" runat="server"
DataSourceID="SqlDataSourceAttribValues">
<EmptyDataTemplate>
<table runat="server" style="">
<tr><td>No data was returned.</td></tr>
</table>
</EmptyDataTemplate>
<ItemTemplate>
<tr style="">
<td><asp:Label ID="equipment_attrib_value_detailsLabel" runat="server" Text='<%# Eval("equipment_attrib_value_details") %>' /></td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table ID="itemPlaceholderContainer" runat="server" border="0" style="">
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
The GridView displays all columns fine except the "equipment_attrib_value_details" column where I get "No data was returned."
However, if I take out the asp:ControlParameter which calls upon #head_id and use this hardcoded SELECT statement then I see the correct (albeit hardcoded) values:
SelectCommand="SELECT [equipment_attrib_value_details] FROM [equipment_new_attrib_values] WHERE (equipment_attrib_heading_id = 3) AND (equipment_id = #equipment_id) AND (equipment_attrib_value_deleted = 0)">
Therefore, for some reason, it would appear that the GridViewAttribs value of "equipment_attrib_heading_id" is not being passed to / picked up by the nested asp:ControlParameter
On the off chance, I've also tried replacing:
PropertyName="SelectedDataKey.Values[equipment_attrib_heading_id]"
With:
PropertyName="SelectedValue"
But this didn't resolve the issue either, still not data was returned.
If it helps, I'm using Visual Studio 2010 with ASP.NET4 (vb).
What you could try is using a hidden field and use that control for the controlparameter
<asp:TemplateField HeaderText="equipment_attrib_value_details" SortExpression="equipment_attrib_value_details">
<ItemTemplate>
<asp:HiddenField runat="server" ID="heading_id" Value='<%# Eval("equipment_attrib_heading_id") %>' />
<asp:SqlDataSource ID="SqlDataSourceAttribValues" runat="server"
ConnectionString="<%$ ConnectionStrings:customer_support_devConnectionString %>"
ProviderName="<%$ ConnectionStrings:customer_support_devConnectionString.ProviderName %>"
SelectCommand="SELECT [equipment_attrib_value_details] FROM [equipment_new_attrib_values] WHERE (equipment_attrib_heading_id = #head_id) AND (equipment_id = #equipment_id) AND (equipment_attrib_value_deleted = 0)">
<SelectParameters>
<asp:QueryStringParameter Name="equipment_id" QueryStringField="id" Type="Int32" />
<asp:ControlParameter ControlID="heading_id" Name="head_id" PropertyName="Value" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:ListView ID="ListViewAttribValues" runat="server"
DataSourceID="SqlDataSourceAttribValues">
<EmptyDataTemplate>
<table id="Table2" runat="server" style="">
<tr><td>No data was returned.</td></tr>
</table>
</EmptyDataTemplate>
<ItemTemplate>
<tr style="">
<td><asp:Label ID="equipment_attrib_value_detailsLabel" runat="server" Text='<%# Eval("equipment_attrib_value_details") %>' /></td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table ID="itemPlaceholderContainer" runat="server" border="0" style="">
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
</ItemTemplate>
</asp:TemplateField>
This only works (it seems) if the HiddenField is inside the same ItemTemplate. If the DataSource is somewhere outside the TemplateField, in cases where you want to data-populate a control that is say on another column or field of the GridView, then the HiddenField will not work, as it's technically hidden.
The way to overcome this is in code-behind. Here is how I do it...
I have a TemplateField that is referring to #StudentID, which is actually a HiddenField in another TemplateField.
<asp:TemplateField HeaderText="Currently<br/>Tracking<br/>(past weeks)">
<ItemTemplate>
<asp:CheckBoxList ID="listWeeksTracking" runat="server" DataSourceID="sdsTETpastWeeks" DataTextField="WeekNo" DataValueField="WeekNo"
OnDataBound="listWeeksTracking_DataBound" OnDataBinding="listWeeksTracking_DataBinding"></asp:CheckBoxList>
<br />
<asp:SqlDataSource ID="sdsTETpastWeeks" runat="server" ConnectionString="<%$ ConnectionStrings:ATCNTV1ConnectionString %>"
SelectCommand="SELECT tb.WeekNo, ISNULL((SELECT TOP 1 ts.ETRTWtracking FROM tblTETMeetingStudent AS ts INNER JOIN tblTETMeeting AS tm ON tm.TETmeetingID = ts.TETmeetingID AND tm.WeekNo = tb.WeekNo WHERE ts.StudentID = #StudentID),0) AS Tracking FROM tblTETInstructionalTrainingBlocks AS tb WHERE tb.WeekNo <= #WeekNo AND tb.Active = 1 AND tb.YearNum = YEAR(#TETdate) ORDER BY tb.WeekNo">
<SelectParameters>
<asp:Parameter Name="StudentID" Type="string" />
<asp:ControlParameter ControlID="ddlWeekNo" Name="WeekNo" PropertyName="SelectedValue" Type="int16" />
<asp:ControlParameter ControlID="lblTETdate" Name="TETdate" Type="DateTime" />
</SelectParameters>
</asp:SqlDataSource>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Wrap="False" />
</asp:TemplateField>
So I define the #StudentID parameter as simple a parameter, and not a ControlParameter, is it won't be able to pick up the hiddenfield elsewhere in my GridView.
In code-behind (C#), I trap the Selecting event via the DataBinding.
And in there I specifically look for the row in relation to the control I've just populated (or about to), and then I look for the HiddenField.
protected void listWeeksTracking_DataBinding(object sender, EventArgs e)
{
//set the parameter for the StudentID here as using hiddenfields does not work directly in asp.net, as they are hidden!
CheckBoxList cbl1 = (CheckBoxList)sender;
GridViewRow gvRow = (GridViewRow)cbl1.NamingContainer;
if (gvRow != null)
{
SqlDataSource sdsTETpastWeeks = (SqlDataSource)gvRow.FindControl("sdsTETpastWeeks");
HiddenField hfStudentID = (HiddenField)gvRow.FindControl("hfStudentID");
if (hfStudentID != null) sdsTETpastWeeks.SelectParameters["StudentID"].DefaultValue = hfStudentID.Value.ToString();
}
}
Voila!
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...
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.
I am using visual studio 2010 to create a form where you can edit,delete, or insert data from an accessdatabase. When I try to run the form in a web browser I get the error "Query input must contain at least one table or query." I believe that the problem lies with my code/syntax but I am unable to determine the cause of the problem. I added some of my code below and any help/hints would be greatly appreciated. Thank You.
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/database.accdb" SelectCommand="SELECT * FROM [database]"
DeleteCommand="DELETE FROM [database] WHERE ([EmployeeID] = #EmployeeID)"
UpdateCommand="UPDATE [database] SET [Phone]=#Phone,[FirstName] = #FirstName, [LastName]= #LastName WHERE ([EmployeeID] = #EmployeeID)"
InsertCommand="INSERT INTO [database] (Phone,FirstName,LastName) VALUES (#Phone,#FirstName,#LastName) WHERE ([EmployeeID] = #EmployeeID)">
<InsertParameters>
<asp:formparameter name="Phone" formfield="tbPhone" />
<asp:formparameter name="FirstName" formfield="tbFirstName" />
<asp:formparameter name="LastName" formfield="tbLastName" />
</InsertParameters>
</asp:AccessDataSource>
<asp:GridView ID="gvEmployee" runat="server" AutoGenerateColumns="False"
DataSourceID="AccessDataSource1" DataKeyNames="EmployeeID"
AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" AutoGenerateInsertButton="True"
EmptyDataText="There are no data records to display." Width="372px">
<Columns>
<asp:BoundField DataField="Phone" HeaderText="Phone"
SortExpression="Phone" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName"
SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName"
SortExpression="LastName" />
</Columns>
</asp:GridView>
</td>
</tr>
<tr>
<td>
Phone Number:
<asp:TextBox ID="tbPhone" runat="server"></asp:TextBox><br />
First Name:
<asp:TextBox ID="tbFirstName" runat="server"></asp:TextBox> <br />
Last Name:
<asp:TextBox ID="tbLastName" runat="server"></asp:TextBox> <br />
<asp:button id="Button1" runat="server" text="New Employee" onclick="InsertEmployee" />
</td>
</tr>
What is [Database]? Is that your table name? You need to specify a table name, such as PERSONS, or Employees?
SELECT * FROM [database]
try something like
SELECT * FROM Employee
Try this now
SELECT Phone,FirstName,LastName,EmployeeID FROM [employees]
If that works, it means some sort of field in the Employees table is something that can't be handled... Since the above triggers an error, it means the code can't handle an Autonum field. Try the following:
SELECT Phone,FirstName,LastName,CAST(EmployeeID as INT) as EmployeeID
FROM [employees]
Try taking the where clause entirely off the INSERT SQL
InsertCommand="INSERT INTO [database] (Phone,FirstName,LastName) VALUES (#Phone,#FirstName,#LastName) "
I am trying to perform a single search on a single column of data in an asp:GridView, however I want multiple filter (search) boxes above each column so one could search within its own perspective column. What would clearly fix this theoretically is to have multiple FilterExpressions. I am using VB and am very new and easily misunderstood with VB, please bare with:
PS. I have gotten it to work no problem when only having ONE filter (search) box, this currently doesn't do anything
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="xxx"
ProviderName="xxxx"
SelectCommand="SELECT [ddiID], [volusionID], [Customer], [email], [Total], [SumOfTotal] FROM [BBnewsalesQry] ORDER BY [Customer]"
FilterExpression="customer like '%{0}%' OR ddiID like '%{0}%'">
<FilterParameters>
<asp:ControlParameter Name="ddiID" ControlID="ddiIDSearch" PropertyName="Text" />
<asp:ControlParameter Name="customer" ControlID="txtSearch" PropertyName="Text" />
</FilterParameters>
</asp:SqlDataSource>
<div>
<b>DDI Search:</b> <asp:TextBox ID="ddiIDSearch" runat="server" />
<b>Customer Search:</b> <asp:TextBox ID="txtSearch" runat="server" />
<asp:ImageButton ID="btnSearch" ImageUrl="http:xxx" runat="server" />
<asp:ImageButton ID="btnClear" ImageUrl="http:xxx" runat="server" />
</div>
Then inside the GridView:
<asp:TemplateField HeaderText="ddiID" SortExpression="ddiID">
<ItemStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="lblddiid" Text='<%#HighlightText(Eval("ddiid")) %>'
CssClass="TextField" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="volusionID" HeaderText="volusionID" ReadOnly="True" SortExpression="volusionID" />
<asp:TemplateField HeaderText="customer" SortExpression="customer">
<ItemStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="lblcustomer" Text='<%#HighlightText(Eval("customer")) %>'
CssClass="TextField" runat="server" />
</ItemTemplate>
</asp:TemplateField>
you are referencing the same parameter twice - try the following:
FilterExpression="customer like '%{0}%' OR ddiID like '%{1}%'"
I have resolved the problem of create two or more "Like clause" in the "Where" statement using:
Where CHARINDEX(#Par1, Col1)<>0) and ...