GridView to FormView - DataBind

M

mosscliffe

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
 
M

mosscliffe

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
 
G

Guest

Why not just set a control parameter for the datasource that is bound to the
formview, to the SelectedValue property of the gridview?
 
M

mosscliffe

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
 
G

Guest

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.
 
M

mosscliffe

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top