Turning information from a datasource into links - asp.net

I have a web application where I am getting data from an oracle database in a gridview.
Can anyone tell me how to turn this data into links to other pages on my web application?
For example, if I am getting data about a list of objects that have their own ID, I want to be able to click the ID and go to a page with information on only that object
This is all the code for my gridview, in SystemGrid_Sorting, I get all the info from the databse, so I can't actually define the properties of my columns.
Thanks in advance
asp:GridView ID="SystemGrid" runat="server" AllowSorting="True" Width="232px" OnSorting="SystemGrid_Sorting" >

This is very easy:
<asp:HyperLinkField DataNavigateUrlFields="ID"
DataNavigateUrlFormatString="DetailPage.aspx?id={0}"
DataTextField="CategoryName" NavigateUrl="DetailPage.aspx" />
Now just set up DetailPage.aspx to call into the database using the ID in the querystring and display whatever you like.

Essentially, given an ID 1234 you need to turn it into an HTML link like:
1234
I don't know whether your gridview tool has a built-in method for constructing such links for you?

Related

Records from table not showing and not edible in AxGridView

Lets say that I want to show records from a table into an AxGridView and make that AxGrivView being able to create, edit and delete a record, are there any good tutorial on how to accomplish that?
EDIT
I'll try and explain what I've done so:
I've this dataset:
with these properties for eg. TrvExpParm_cars:
My user control contains this code:
<dynamics:AxColumn ID="TopRowRight" runat="server">
<dynamics:AxMultiSection ID="AxMultiSection1" runat="server">
<dynamics:AxSection ID="AxSection1" runat="server" Caption="Mine biler" Expanded="true">
<dynamics:AxDataSource ID="dsEPTrvExpParm_cars" runat="server" DataSetName="EPTrvExpParm" ProviderView="TrvExpParm"> </dynamics:AxDataSource>
<dynamics:AxGridView ID="AxGridView_cars" runat="server"
AllowDelete="True" AllowEdit="True" AllowPaging="False" BodyHeight=""
DataKeyNames="RecId" DataMember="TrvExpParm_cars"
DataSetCachingKey="xxxxxxxxxxxxxxxxxxx"
DataSourceID="dsEPTrvExpParm_cars" EnableModelValidation="True">
<Columns>
<dynamics:AxBoundField DataField="Name" DataSet="EPTrvExpParm"
DataSetView="TrvExpParm_cars" SortExpression="Name">
</dynamics:AxBoundField>
<dynamics:AxBoundField DataField="LicensePlate" DataSet="EPTrvExpParm"
DataSetView="TrvExpParm_cars" SortExpression="LicensePlate">
</dynamics:AxBoundField>
</Columns>
</dynamics:AxGridView>
</dynamics:AxSection>
</dynamics:AxMultiSection>
</dynamics:AxColumn>
What I get is an empty grid:
The table EPTrvExpParm_cars contains two fields with 2 records:
I really don't know why I can't see the data from the table. Are there some properties that I need to set or do I need som custom code? According to the Dynamics AX 2012 Enterprise Portal Cookbook, custom code shouldn't be needed, but again it's just a "cookbook"
UPDATE
The relation between TrvExpParm and TrvExpParm_cars is this:
What is the relation between your TrvExpParm and TrvExpParm_cars?
The way your datasource is defined the TrvExpParm is the data provider (providerview) so it will look for a TrvExpParm record (the first) and will try to show the linked TrvExpParm_cars records because in your gridview you choose TrvExpParm_cars as DataSetView.
The following whitepaper should help you do that: Microsoft Dynamics AX 2012 White Paper: Enterprise Portal Development Cookbook
A quote from the document:
AxGridView also includes built-in data modification capabilities. By using AxGridView with the declarative
AxDataSource, you can easily configure and modify data without writing code. [...] AllowInsert, AllowEdit, and AllowDelete properties control the create, read, update, and delete operations on the grid.

Alternate DataNavigateUrlFormatString at run time for Tracking Numbers between two Carriers

I have been creating an order status ASPX page that shows the Date, Carrier, Customer and Tracking Number. The data on this page is generated by a search form where the user can search either via the date or the customer's name. In our SQL Database, for Tracking Number, it only contains the numerical number such as "759102160484401" (Random FedEx Tracking Number). Whenever a search is pulled up I wanted to hyperlink these to the proper tracking papers respectively to each Shipping company. The current output is as follows:
10/8/2012 --- FEDEX --- JAMES FRANCO --- 759102160484401
Now The Problem. We have the current DataNavigateUrlFormatString set to a FedEx url. We would like this to alternate to the UPS link when it detects that the SQL field for Carrier says "UPS". How would I accomplish this? Below is the current line for the Tracking number column for the Tracking.aspx file.
<asp:HyperLinkField DataTextField="TRACKNUM" DataNavigateUrlFields="TRACKNUM" HeaderText="Tracking#" Target="_blank" Text="Tracking#"
DataNavigateUrlFormatString="http://www.fedex.com/Tracking?clienttype=dotcom&ascend_header=1&cntry_code=us&language=english&mi=n&tracknumbers={0}"
HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
Hope this is detailed and much appreciated!
In outline form,
Register an event on OnRowDataBound (Same concept for other databinding controls)
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.onrowdatabound.aspx
Extract from the row the HyperLinkField. Usually using FindControl on the .Row property of the event, or sometimes .Row[x] where x is the index of the cell that holds your control.
Set the DataNavigateUrlFormatString to one string or another depending on what ever lets you know if you need a fedex or ups url.

Calling a MSAcces database query from an aspx in C#

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.

Connecting a gridview to multiple tables linqdatasource

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

What is the best approach for this CRUD search page in ASP.NET

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.

Resources