473,287 Members | 1,413 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

GridView to FormView - DataBind

Following Mr Tabors Video on Databinding I implemented the following
code

In GridViewSelectedIndexChange

I coded DetailsView1.pageindex = gridview1.selectedindex

This works fine for the first page of the binding, but once thr
gridview re-arranges - the formview only ever sees in effect the
rowdisplayedindex

How do I actually bind the formview ID field to the Gridview ID field
of the selected row.

This should be simple

I guess something like Formview.Selected("KeyfieldFieldID) =
Gridview.Selected("KeyFieldID")
but the exact syntax eludes me.

Thanks for any help or pointers

Tim

May 17 '06 #1
5 7804
I am making some progress.

I can now get the correct KeyField ID value from the Selected Item in
the GridView with the following

cint(GridView1.SelectedDataKey.Value)

but how do I link that to the FormView

The formViews PageIndex property is not the way. I have somehow to get
the Formviews Keyfield the same as the data grids and at the moment I
can not work it out.

Please !!!! any help would be most gratefully received.

Tim

May 17 '06 #2
Why not just set a control parameter for the datasource that is bound to the
formview, to the SelectedValue property of the gridview?

"mosscliffe" wrote:
I am making some progress.

I can now get the correct KeyField ID value from the Selected Item in
the GridView with the following

cint(GridView1.SelectedDataKey.Value)

but how do I link that to the FormView

The formViews PageIndex property is not the way. I have somehow to get
the Formviews Keyfield the same as the data grids and at the moment I
can not work it out.

Please !!!! any help would be most gratefully received.

Tim

May 17 '06 #3
If that is the answer fine, but I am afraid you are talking to someone
very unskilled in this and I do not know what a Control Parameter is.

I just need a simple example - please.

I can get it all to work by doing the code myself, but I thought I
would try using all these wonderful controls, but it seems a very steep
learning curve.
Tim

May 17 '06 #4
Below is an example of an SQLDataSource that uses a control parameter, which
takes the value from a DropDownList control.

<asp:SqlDataSource ID="sdsInvoices" runat="server" ConnectionString="<%$
ConnectionStrings:someconnectionString %>" SelectCommand="SELECT
Accounts_InvoiceEntry_Invoices.OrderID, Accounts_InvoiceEntry_Invoices.Date,
Accounts_InvoiceEntry_Invoices.customer,
Accounts_InvoiceEntry_Invoices.customer_order,
Accounts_InvoiceEntry_Invoices.cust_alpha,
Accounts_InvoiceEntry_Invoices.tran_code1,
Accounts_InvoiceEntry_Invoices.tran_code3,
Accounts_InvoiceEntry_Invoices.StatusID,
Accounts_InvoiceEntry_Statuses.StatusDescription FROM
Accounts_InvoiceEntry_Invoices INNER JOIN Accounts_InvoiceEntry_Statuses ON
Accounts_InvoiceEntry_Invoices.StatusID =
Accounts_InvoiceEntry_Statuses.StatusID WHERE
(Accounts_InvoiceEntry_Invoices.StatusID = @StatusID)">
<SelectParameters>
<asp:ControlParameter ControlID="ddlStatusList" Name="StatusID"
PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>

The above bit in the <asp:ControlParameter > tags is the key. the Mane
property matches a parameter within your SQLQuery or stored procedure, in the
above example this is @StatusID. The ControlID property is set to the ID of
the control from which to take the value of the parameter, in the case a
DropDownList control called ddlSelectStatus. This can be any ASP.net
control. The PropertyName property is the property of the control poited to
by ControlID, from which you want to take the value for the parameter. In
this case it takes the SelectedValue from the ddlSelectedStatus control.

In your case you would just set up the DataSource control to return the
values you needed, with a "WHERE ForeignKeyID = @MyParam" type where clause.
Then set up MyParam as a ControlParameter, as in the example above, but set
the controlID to the ID of your GridView and set the PropertyName to
SelectedValue. The just bind this datasource to the FormView using the
DataSourceID property and it will work.

"mosscliffe" wrote:
If that is the answer fine, but I am afraid you are talking to someone
very unskilled in this and I do not know what a Control Parameter is.

I just need a simple example - please.

I can get it all to work by doing the code myself, but I thought I
would try using all these wonderful controls, but it seems a very steep
learning curve.
Tim

May 18 '06 #5
Great - I have got it working as per your example.

Many thanks indeed. I am getting there very slowly. I am discovering
the learning curve, is much steeper than I anticipated, but looking at
the size of the book I have purchased, it should be no surprise.

My next thoughts are to do with databinding and as I am not sure when
they occur, in relation to postback etc, I am going to look at doing
them all myself, in some master page manager routine and then I know
they will not be rebound, if there is such a word, when it is not
needed.

Many thanks again

Tim

May 18 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: craigkenisston | last post by:
In Asp.Net 2.0 I need to create a very special layout with data coming from an ObjectDataSource. It was already working using a GridView, but I need a free layout. So, I dropped the GridView and...
1
by: joechipubik | last post by:
I have a GridView in a FormView that has as its datasource a DataTable that is stored in the session cache. When I first load the page the GridView is displayed correctly, but on subsequent loads...
0
by: DC | last post by:
The problem I'm using the .NET GridView and FormView objects for the first time and im getting the error "An OleDbParameter with ParameterName '@ID' is not contained by this...
0
by: ThePurpleCat | last post by:
Hi, I'm a newbie to ASP.NET programming but not to Visual Studio. I'm having trouble getting my Master-Details page to work. I have a page enabled GridView which is linked to a FormView control...
2
by: needin4mation | last post by:
In a GridView, take for example a delete button. When I click the delete button in my GridView the GridView row is deleted and the GridView rebinds and refreshes the records to show accurately. ...
2
by: sck10 | last post by:
Hello, I have a web page that has a GridView and a FormView, each in its own panel. The GridView shows a list of records in a database. When a row in the GridView is selected the FormView...
0
by: =?Utf-8?B?TGFkaXNsYXYgTXJua2E=?= | last post by:
Hello, I read some msdn and other articles about how does databinding among DataSource controls and FormView / GridView controls works but I still don't fully understand to this blackbox. I have...
0
by: LiamLiamLiam | last post by:
G'day all. I having a problem with my formview. I'll ty to explain my situation as best as i can. I have a page with a search field at the top which is just a simple asp:textbox. Below that i...
3
by: Polaris | last post by:
Hi Experts: I'm using asp.net 2.0 with Visual Studio 2005. I'm trying to use the GridView to display data. I need to programmatically add rows into the GridView. So far could not find a way...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.