Friday, March 30, 2012

How to control SqlDataSource if we know only DataSourceID ?

Anyone can help me ?Smile

Can you explain your issue? The DataSourceID points to the ID of your SqlDataSource. The SqlDataSource defines a SelectCommand which builds the collection of items which are bound to your databound control.

You can even have more than 1 databound control on the page with the same DataSourceID, like a GridView and a DetailsView. As you select a row in the GridView you can use the DetailsView to edit the row. There are many examples online for databound controls.

Try this...

http://www.asp.net/learn/dataaccess/default.aspx?tabid=63

|||

In context I have an DataSourceID, I want to change SelectCommand of SqlDataSource(before I don't know how to do this-this is my problem)

But now I know -the decision is using method FindControl

anyway Thank you very much !

Now I have a new question !

The question is how to know column's name of DataSource(not DataSet) ?

Do you know this ?

|||

To update the SelectCommand you can do it manually in the code view as opposed to design view. You can also use the wizard to update the SqlDatasource.

For knowing the column's name, that all depends on the Datasource. If the Datasource is not a DataSet and is instead a collection of objects the column name could be one of the properties on the objects.

Or are you thinking of a DataTable? When a SQL result is bound to a GridView using a SqlDatasource it does return a DataSet and it assumes it will use the first DataTable on the DataSet.

ds.Tables[0]

Is this what you needed to know?

|||

offwhite:

To update the SelectCommand you can do it manually in the code view as opposed to design view. You can also use the wizard to update the SqlDatasource.

For knowing the column's name, that all depends on the Datasource. If the Datasource is not a DataSet and is instead a collection of objects the column name could be one of the properties on the objects.

Or are you thinking of a DataTable? When a SQL result is bound to a GridView using a SqlDatasource it does return a DataSet and it assumes it will use the first DataTable on the DataSet.

ds.Tables[0]

Is this what you needed to know?

reality I don't understand you !

All I have :that is SqlDataSource

All I need :that is names of columns

But I don't know how...

:(

No comments:

Post a Comment