GridView to FormView - DataBind

Discussion in 'ASP .Net' started by mosscliffe, May 17, 2006.

  1. mosscliffe

    mosscliffe Guest

    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
     
    mosscliffe, May 17, 2006
    #1
    1. Advertising

  2. mosscliffe

    mosscliffe Guest

    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
     
    mosscliffe, May 17, 2006
    #2
    1. Advertising

  3. 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
    >
    >
     
    =?Utf-8?B?Y2xpY2tvbg==?=, May 17, 2006
    #3
  4. mosscliffe

    mosscliffe Guest

    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
     
    mosscliffe, May 17, 2006
    #4
  5. 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
    >
    >
     
    =?Utf-8?B?Y2xpY2tvbg==?=, May 18, 2006
    #5
  6. mosscliffe

    mosscliffe Guest

    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
     
    mosscliffe, May 18, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SnVyZ2VuIEFwcGVsbw==?=

    Preventing DataBind in a FormView

    =?Utf-8?B?SnVyZ2VuIEFwcGVsbw==?=, Mar 30, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    5,674
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Mar 30, 2006
  2. =?Utf-8?B?eXVjaGFuZw==?=
    Replies:
    0
    Views:
    541
    =?Utf-8?B?eXVjaGFuZw==?=
    Apr 15, 2006
  3. Jai
    Replies:
    0
    Views:
    2,308
  4. mharness
    Replies:
    2
    Views:
    496
  5. Michael
    Replies:
    0
    Views:
    248
    Michael
    Dec 29, 2003
Loading...

Share This Page