Below are the two controls I am trying to use, but neither one will allow me to get the data. Is this something I should be doing in C#? The select command works in MSAccess, because that is where I created it. qcustcnt is a query. The select I pasted in is also a query, but VS2010 doesn't seem to want me to use them, so I tried to bring it insto VS2010.
<asp:AccessDataSource ID="AccessDataSource2" runat="server"
DataFile="~/App_Data/cbf.accdb"
SelectCommand="SELECT DISTINCTROW customer.custsales, Count(*) AS [Count Of customer],
qcustcnt.CountOfcustsales, [count of customer]/[countofcustsales] AS salespercent
FROM customer, qcustcnt
GROUP BY customer.custsales, qcustcnt.CountOfcustsales;">
</asp:AccessDataSource>
<telerik:RadChart ID="RadChart2" runat="server"
DataSourceID="AccessDataSource2">
</telerik:RadChart>
I have it working now. What I ended up doing was removing all the data Access Controls. I added one and that allowed me to use the Queries. When I added the second one it would not. I don't know why but it appeered to be pointing to a database that didn't exist. I deleted that control and copied and Paisted the first control to create a second one and that allowed me to access the Queries in the database. I still don't know whats going on, but I have moved passed the problem.
Related
I have a simple asp FormView on my page, it's working fine and everything, but I noticed the page is somewhat slow to load up (2-3 seconds), when there's really no reason for it, it's such a simple page.
The problem is that the FormView is using a SqlDataSource, which is using a 'heavy' select statement, basically grabbing all the fields and all rows of a profile table (name, address, phone, etc.). I'm assuming the FormView needs to get all the records so the Paging works correctly, but is there a way to code it or an attribute I can use so it doesn't grab every row and column but just all the columns of the current NameId?
asp:
<asp:FormView ... DataSourceId="sdsNames" AllowPaging="True" DataKeyNames="NameId">
<EditItemTemplate>....</EditItemTemplate>
<InsertItemTemplate>...</InsertItemTemplate>
<ItemTemplate>
<asp:Label Text='<%# Eval("Name") %>'.../>
...
</ItemTemplate>
</asp:FormView>
<SqlDataSource ID="sdsNames" ... SelectCommand="SELECT * from tblNames">
I tried changing the SelectCommand to
SELECT * from tblNames where NameId=1
since the initial page should show the first entry. But then I lose the pagination, basically no way to view the next record.
What the Page looks like:
There is not a lot you can do to improve performance here. You're correct, the SqlDataSource does slow things down because it retrieves all of the rows from your table.
There are a couple of different approaches that come to my mind:
Remove fields from your query.
This is the simplest solution, though it might not apply to your situation. If there are fields you don't need to display / modify, remove them. So, rather than SELECT * FROM..., you have SELECT LName, FName, Mname FROM...
You're still getting every row, but at least there is less data in each row.
You could switch to the ObjectDataSource control.
I haven't used this control much, but MSDN says that it performs a little better, because it doesn't always have to retrieve every row:
Some data sources, such as the ObjectDataSource control, offer more
advanced paging capabilities. In these cases the FormView control
takes advantage of the data source's more advanced capabilities to
gain better performance and flexibility while paging. The number of
rows requested may vary depending on whether the data source supports
retrieving the total row count.
You could move away from the datasource controls.
This probably involves more complexity than what you're looking for, but it is the most flexible approach. You can retrieve just the columns and rows you want. You can create a PagerTemplate, and set the values when the FormView is databound. You would have to handle the PageIndexChanging and PageIndexChanged events to change the paging values yourself.
Goal
What I need is to display a SQL DataTable to the user on a webpage through ASP.NET and allow them to select a number of rows very quickly and easily, and then hit any of a number of different buttons to signify different operations. The selected rows are to be sent off to be processed (generally sent to a webservice or similar through codebehind). This is a somewhat generic solution, as I will be using this same setup in many places - thus the data, and the available operations will be different.
The goal is to be able to know basically nothing about the data - that is for the user to understand. If this concept is already impossible (though I believe it is not), please let me know.
Pulling from T-SQL (SQL Server 2008 R2 or later).
Using ASP.NET to make aspx webpage. Codebehind is done in VB.NET, in both cases we're using 4.0
I'm fluent in C# and VC++, so if you can't easily translate your code, don't worry about that.
The problem
My problem has been creating a row selection process for the user which persists while sorting or paging the table, is quick for the user and relatively quick in response time, and which is reflected in the GridView's bound data (as this allows me to use a filter on a DataView to produce a DataTable for passing). If there's another way to know the selected rows then I'm all game so long as it is persistant and quick for the user.
I'm not debugging and I'm not having syntax issues (I do not believe) - I don't know how to proceed.
I don't necessarily need code as a solution - I need to understand if my metaphor is either bad practice, or simply uncommon and thus not well supported. In either case, what is an appropriate way to proceed? If nothing else, where do I look for a solution besides endless API and Tutorials?
My original plan
I wanted to use asp:GridView for binding the DataTable pulled from TSQL since I can auto-generate columns. This allows me to display data without needing to know what it is. I planned to add a specific boolean Column (left most) for storing the User's row selection. Then I can simply run a filter on the DataTable to produce a DataView, get the resulting DataTable from that DataView, and pass it down the chain.
All the columns except our specific selection one would be Read-Only. The user isn't editing data - their selecting records and view their selection side-by-side with the viewable relevant data.
Of note, I planned to check for name collision so our added Column doesn't collide with any existing Column in the DataTable - I'd rename it as needed using 'Select' followed by an integer produced by looping through, comparing my name to other columns, incrementing as needed.
I presumed that once I set this up, it would just handle itself: the user could click the resulting checkbox column cell's and it would change the data on the fly. The point of saving the selection was their selection persisted through sorting and paging for convenience (I save the GridView's DataSource and re-bind when necessary). It didn't really matter if the user refreshed the page and completely and lost their checkboxes - they would need to review any changes/new data, and they wouldn't need more then a brief moment to check off whatever they wanted.
This did not happen.
I found that AutoGenerateColumns does not produce checkboxes for boolean DataColumns. It produces text, so I end up with the word 'True' or 'False'.
I began looking for a way to get check boxes in the cells for a boolean DataColumn. I found that for the added boolean column, I could bind an asp:CheckBoxField to it using the attribute DataField. Of course, I have to figure out how to point it at a variable DataField...
<Columns>
<asp:CheckBoxField DataField="Select" HeaderText="Select"
ReadOnly="False" SortExpression="Select">
<ItemStyle HorizontalAlign="Center" />
</asp:CheckBoxField>
</Columns>
However, because a GridView is designed for Row-By-Row editing, all the resulting CheckBoxes are disabled and cannot be checked. This is because their containing row is not in Edit Mdoe. I do not want to enable Row-By-Row editing using a button or similar metaphor as the user often needs to check off several rows. More clicks is bad, and annoying. They should be focused soley on their data and making their selection, not worrying about remembering to enter and end edit mode. Also, the metaphor seems poorly placed here since the checkboxes are the -ONLY- editable data - and are not part of the represented data.
I could, of course, make a new class which inherits from GridView, overload the method which generates columns to produce checkboxes instead of text fields - but I felt there had to be a more straightforward path. Maybe this is the way to go? But maybe it would have the same editing issue as above - I'm not sure.
So, next I tried looking at using an asp:TemplateField as a column in my GridView. This TemplateField contains an asp:CheckBox who's Checked state is based on the underlying bound data value. The issue here is trying to make changing the check-state update that bound value. I would need some way of looking up a GridView value I could then use to find the same row in the DataTable. I've seen great examples using a Primary Key. While I could assume everyone keeps a Primary Key for any possible table, this might not be the case! I could further add a Primary Key myself, but now it looks like I would be adding and removing two columns before I pass a DataTable off to a WebService instead of just one. Again, I also would need to be able to assign a Column name which is dynamic to avoid collision.
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox runat="server" ID="CheckBox"
Checked="<%# DataBinder.Eval(Container.DataItem, "Select") %>"
AutoPostBack="true" OnCheckedChanged="SelectCheckBox_CheckChanged" />
</ItemTemplate>
</asp:TemplateField>
I stopped myself - This path is also fairly indirect. Surely there is a much cleaner, simpler way to do this. Is it uncommon for someone to display Read-Only data where records are selected to be submitted, in one fashion or another, for processing/updating/alteration?
Is my choice of GridView poor? I haven't yet found another good way to represent Table data.
I am implementing an online parking reservation system and I need to bind a table with 2 Controls.
for example the user selects a Reservation start date and the parking location from a RadioButtonList and then a button (Search Availability) is pushed to fetch the parking from the database according to the Date selected and Location.
the question is: How can I bind the (Reservation Start Date Control) with (RadioButtonList) to both search in the database? and what would be the Sql Query?
Regards.
This is pretty basic stuff so you've got a lot of work ahead of you.
On your aspx page, you will want to use a SqlDataSource and add two ControlParameters to the SelectParameters, one for the RadioButtonList, one for the TextBox/Calendar with the date. Then create a GridView control to display the results and set the DataSource of the gridview to be the SqlDataSource.
Depending on your database schema, the SQL Statement will look something like this:
SELECT * FROM [Parking] WHERE [LotID] = #LotID AND [Date] = #Date AND [Reserved] = FALSE;
However, I have done reservation systems in the past, and queries to find available spots for a particular day are rarely simple. I would suggest worrying about writing the SQL query first and then getting the web page to run the query later. If you post information about your table schema and tag it as a SQL question you'll probably have better luck.
Hope this helps.
I'm just playing with some linq and asp.net - absolute beginner so I'm not even sure exactly how to ask my question.
Anyway, I have a MSSQL database with asp membership info in it. For various reasons (mainly to store profile info in clear columns instead of all in one) I'm using a custom profile provider so my profile information is spread across a few tables in my database.
I have the normal aspnet_membership and aspnet_profle, but then I also have a tblUserProfile table, in which I store a bunch of user profile information like first name, phone number etc. The tblUserProfile also has a companyID in it, referring to a seperate table with a list of companies in it.
All tables have a GUID UserId as their key.
I created a datamodel diagram that contains all the tables I'm using and it shows the keys linking up etc properly.
So now I have a gridview that uses a LinqDataSource that is connected to the aspnet_membership table. This bit so far works well, I'm able to display all the info in the aspnet_membership table. I also figured out how to show the company a user is in like this:
<asp:TemplateField HeaderText="Company" SortExpression="tblUserProfile.Company.CompanyName">
<ItemTemplate>
<%#Eval("tblUserProfile.Company.CompanyName") %>
</ItemTemplate>
What I can't figure out is how to make changes to this save to the database. If I change direct fields in aspnet_membership table, they update properly.
I created a dropdown showing all available companies, you can select the company to change directly in the grid, but when I try to update it reverts back to the original value.
<asp:TemplateField HeaderText="Company" SortExpression="tblUserProfile.Company.CompanyName">
<ItemTemplate>
<%#Eval("tblUserProfile.Company.CompanyName") %>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="CompanyDropDownList"
DataSourceID="CompanyDataSource"
DataValueField="Id"
DataTextField="CompanyName"
SelectedValue='<%#Bind("tblUserProfile.CompanyID") %>'
runat="server">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
I'm not sure if it's because my datasource is connecting to one table (aspnet_membership) but the value I'm trying to change is in tblUserProfile. It seems that I can retrieve/display values from the other tables connected via foreign keys, but can I also update values in those tables?
Sorry for a long winded question, but I'm pretty new to this so aren't sure exactly where the problems are otherwise I'd be more specific.
Thanks for any pointers
It sounds like you are trying to use the automatic updating provided by the LinqDataSource but as you point out, that doesn't work properly with joined data. That is a limitation of the automatic updating. You can however subscribe to one of the OnUpdating events and write some code to handle the additional updating. How exactly that should be written depends on the names of your key values, etc. but there should be some information about it on this site and elsewhere.
You can create a custom databound control to edit the sub objects
public class CompositeBoundField : BoundField
{
protected override object GetValue(Control controlContainer)
{
object item = DataBinder.GetDataItem(controlContainer);
return DataBinder.Eval(item, this.DataField);
}
}
And then use this in a page like so:
<cc:CompositeBoundField DataField="aspnet_Membership.Email" HeaderText="Email"/>
Then add this to the web.config:
<pages>
<controls>
<add assembly="App_Code" namespace="CustomControls" tagPrefix="cc"/>
</controls>
Let me know if this helps by giving me an up-check. It is possible to create other bound fields for checkbox or other types. This may have been the original author/source for this method:
http://iridescence.no/post/FixingBoundFieldSupportforCompositeObjects.aspx
I'm building a heavily CRUD based ASP.NET website and I've got to the phase of the project where I'm trying to build a search webpage that shows the user different subsets of a certain important table based on parameters they enter such as dates and different text fields.
I can't use a fixed SQL statement, because depending on whether they search by date or by something else, the SQL would be different, so instead I have been generating a results list using a table web control that starts out invisible and then is filled and set to visible once the user identifies a search they want to make. I used a table control because its easy to create and modify in the code behind, and I was able to make the needed calls to the database and populate that table as required.
However, the second thing I need with this search page, is the ability to allow the user to select a record from the results and then go edit it using the rest of the CRUD based pages on the site. To do that, I created asp:buttons in the table and gave them all different ids and the same event handler. But since I created the buttons dynamically, it seems the event disappears on callback and my scheme fails, so I'm taking a second look at how to do this.
My current code for the events looks like:
tempcell = new TableCell();
Button tempbutton = new Button();
tempbutton.Text = "Go";
tempbutton.ID = "gobutton" + rowN;
tempbutton.Visible = true;
tempbutton.Click += new EventHandler(tempbutton_Click);
tempcell.Controls.Add(tempbutton);
temprow.Cells.Add(tempcell);
My results table is declared like this:
<asp:Table ID="ResultTable" visible="false" runat="server"
GridLines="Both" CellSpacing="8">
</asp:Table>
I'd like to be able to identify which record the user selected, so I can send that info on to another page. And of course, I still need to be able to generate results for several different search criteria. Currently I have date, template and code based searches that lead to different stored procedures and different parameters based on what the user has entered.
Any suggestions on this? It seems like the data grids and repeaters require SQL statements in advance to work properly, so I'm not sure how to use them, but if I could then the item command approach would work with the buttons.
Your event will hook up successfully if the button is recreated in the page load event.
Otherwise, use a GridView. It is the perfect solution for simple CRUD, and you can control it as much as you need.