473,396 Members | 1,599 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,396 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 7805
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.