473,796 Members | 2,464 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView to FormView - DataBind

Following Mr Tabors Video on Databinding I implemented the following
code

In GridViewSelecte dIndexChange

I coded DetailsView1.pa geindex = gridview1.selec tedindex

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

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.Select ed("KeyfieldFie ldID) =
Gridview.Select ed("KeyFieldID" )
but the exact syntax eludes me.

Thanks for any help or pointers

Tim

May 17 '06 #1
5 7832
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:SqlDataSou rce ID="sdsInvoices " runat="server" ConnectionStrin g="<%$
ConnectionStrin gs:someconnecti onString %>" SelectCommand=" SELECT
Accounts_Invoic eEntry_Invoices .OrderID, Accounts_Invoic eEntry_Invoices .Date,
Accounts_Invoic eEntry_Invoices .customer,
Accounts_Invoic eEntry_Invoices .customer_order ,
Accounts_Invoic eEntry_Invoices .cust_alpha,
Accounts_Invoic eEntry_Invoices .tran_code1,
Accounts_Invoic eEntry_Invoices .tran_code3,
Accounts_Invoic eEntry_Invoices .StatusID,
Accounts_Invoic eEntry_Statuses .StatusDescript ion FROM
Accounts_Invoic eEntry_Invoices INNER JOIN Accounts_Invoic eEntry_Statuses ON
Accounts_Invoic eEntry_Invoices .StatusID =
Accounts_Invoic eEntry_Statuses .StatusID WHERE
(Accounts_Invoi ceEntry_Invoice s.StatusID = @StatusID)">
<SelectParamete rs>
<asp:ControlPar ameter ControlID="ddlS tatusList" Name="StatusID"
PropertyName="S electedValue"
Type="Int32" />
</SelectParameter s>

The above bit in the <asp:ControlPar ameter > 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 ddlSelectedStat us 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 ControlParamete r, 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
2211
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 added something like this: So, I'm trying something like : <div> <table> <tr> <td>
1
5216
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 the GridView does not display. I've debugged the DataTable and even when it has data and is bound to the GridView, when the page loads the GridView is not displayed. I set the datasource and then bind the GridView. I've tried disabling the...
0
3588
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 OleDbParameterCollection" whenI try to write a new record. Delete and Modify work fine its just the add record function causes the error.
0
4749
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 through an objectdatasource. The paging on my GridView works fine except that when I change the page the FormView does not update. I tried setting the selectedindex to 0 in the GridView's PageIndexChanged event and manually binding the formview...
2
5640
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. Problem: I have a GridView that has a select. This select gives a FormView control the data to open. I set the GridView visible to false. I have only my FormView open. This FormView is used to edit, have other DetailsViews that open etc.
2
4505
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 Panel becomes visible. pnlGridViewSearchList pnlFormView The problem that I am having is that if I set the FormView Panel's
0
1998
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 few questions and hopefully you can provide me some answers. 1. Best place for DataBinding. Where is the best place for calling DataBind method? Is it possible to say don't bind controls for this postback and use current values instead? These...
0
2140
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 have a gridview which displays the results of the search. if no search is entered, then the gridview shows all records. Below the gridview i have a formview for inserting and editing the records. when a user clicks on one of the records in the...
3
26286
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 to do it. I appreciate it if any one can show a piece of code doing that.
0
9680
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9528
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10456
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10230
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10012
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6788
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5575
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.