Home All Groups Group Topic Archive Search About
Author
28 Jun 2006 9:26 PM
TJHerman
Is there any way to refer to the specific field values in an sqldatasource in
a formview without doing the sqldataadapater, datatable, etc.?

Author
29 Jun 2006 3:41 PM
Phillip Williams
You can access the fields values through the command object which is passed
to the event handlers.   For example one might add to the markup:
OnSelected ="sqldsOrderDetail_Selected"

and then during handling the Selected event, one might write:

void sqldsOrderDetail_Selected(object sender, SqlDataSourceStatusEventArgs e)
        {
            //get a reference to the command object used by the SqlDataSource
            System.Data.Common.DbCommand command = e.Command;
            //you can access the parameter value
            Response.Write(command.Parameters["@OrderID"].Value.ToString());
        }
Show quoteHide quote
"TJHerman" wrote:

> Is there any way to refer to the specific field values in an sqldatasource in
> a formview without doing the sqldataadapater, datatable, etc.?
Author
29 Jun 2006 5:44 PM
TJHerman
You wouldn't happen to know how this is written in VB? (I'm really pushing my
luck!)

Show quoteHide quote
"Phillip Williams" wrote:

> You can access the fields values through the command object which is passed
> to the event handlers.   For example one might add to the markup:
> OnSelected ="sqldsOrderDetail_Selected"
>
> and then during handling the Selected event, one might write:
>
> void sqldsOrderDetail_Selected(object sender, SqlDataSourceStatusEventArgs e)
>         {
>             //get a reference to the command object used by the SqlDataSource
>             System.Data.Common.DbCommand command = e.Command;
>             //you can access the parameter value
>             Response.Write(command.Parameters["@OrderID"].Value.ToString());
>         }
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "TJHerman" wrote:
>
> > Is there any way to refer to the specific field values in an sqldatasource in
> > a formview without doing the sqldataadapater, datatable, etc.?
Author
29 Jun 2006 8:31 PM
Phillip Williams
No problem. You are welcome. It would be great if every poster indicates the
development platform and language they are using within the body of the
question (e.g. ASP.NET2.0 VB would make the response more relevant)

'In this event-handling you access the parameters in the SqlDataSource
    Protected Sub SqlDataSource1_Selected(ByVal sender As Object, ByVal e As
SqlDataSourceStatusEventArgs)
        Dim command As System.Data.Common.DbCommand = e.Command
        'you can access the parameter value
        If command.Parameters.Count > 0 AndAlso Not
command.Parameters("PK_ID") Is Nothing Then
            Response.Write(command.Parameters("@PK_ID").Value.ToString())
        End If

    End Sub
    'if you want to access any field value within the retrieved data then
use the DataItem
    'upon handling the FormView.DataBound event
    Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As
System.EventArgs)
        Dim frmV As FormView = DirectCast(sender, FormView)
        Dim drv As System.Data.DataRowView = DirectCast(frmV.DataItem,
System.Data.DataRowView)
        Response.Write(drv("Company").ToString())
    End Sub--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


Show quoteHide quote
"TJHerman" wrote:

> You wouldn't happen to know how this is written in VB? (I'm really pushing my
> luck!)
>
> "Phillip Williams" wrote:
>
> > You can access the fields values through the command object which is passed
> > to the event handlers.   For example one might add to the markup:
> > OnSelected ="sqldsOrderDetail_Selected"
> >
> > and then during handling the Selected event, one might write:
> >
> > void sqldsOrderDetail_Selected(object sender, SqlDataSourceStatusEventArgs e)
> >         {
> >             //get a reference to the command object used by the SqlDataSource
> >             System.Data.Common.DbCommand command = e.Command;
> >             //you can access the parameter value
> >             Response.Write(command.Parameters["@OrderID"].Value.ToString());
> >         }
> > --
> > HTH,
> > Phillip Williams
> > http://www.societopia.net
> > http://www.webswapp.com
> >
> >
> > "TJHerman" wrote:
> >
> > > Is there any way to refer to the specific field values in an sqldatasource in
> > > a formview without doing the sqldataadapater, datatable, etc.?
Author
29 Jun 2006 3:57 PM
TJHerman
Thank you very much! I will definitely experiment with this! I'm new to the
dotnet but with individuals like you willing to share you knowledge, I'm very
encouraged!

Show quoteHide quote
"TJHerman" wrote:

> Is there any way to refer to the specific field values in an sqldatasource in
> a formview without doing the sqldataadapater, datatable, etc.?