473,387 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

SqlDataSource CurrentItem

Jed
I have a SqlDataSource bound to DataView control. When the selected index of
the DataView changes I would like to get the value of a field (column) from
the bound Row. The column's visible property is false. I thought I would be
able to handle the selected event of the SqlDataSource and get the Row data,
but there is nothing there.

Where are the SqlDataSourceView items? The DataView's selected item doesn't
have a DataItem, so I can't access the Row. If I show the column I want to
hide, I can access the "Text" of the GridView column, but the text has been
HtmlEncoded. (and either way of course I don't want it in the grid).

Where is the CurrentItem and can it be accessed?
Dec 6 '05 #1
4 3457
You might add the DataKeyNames to the declaration of the GridView then while
handling the SelectedindexChanged you would get that key, which you can use
to query the database programmatically, e.g.
string strKey = ((GridView)sender).SelectedDataKey.Value.ToString( );

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Jed" wrote:
I have a SqlDataSource bound to DataView control. When the selected index of
the DataView changes I would like to get the value of a field (column) from
the bound Row. The column's visible property is false. I thought I would be
able to handle the selected event of the SqlDataSource and get the Row data,
but there is nothing there.

Where are the SqlDataSourceView items? The DataView's selected item doesn't
have a DataItem, so I can't access the Row. If I show the column I want to
hide, I can access the "Text" of the GridView column, but the text has been
HtmlEncoded. (and either way of course I don't want it in the grid).

Where is the CurrentItem and can it be accessed?

Dec 6 '05 #2
Jed
Thanks for the reponse. I can't believe that I would have to call back to the
database again, but after messing with this for some time, that really does
seem to be the emerging solution.

"Phillip Williams" wrote:
You might add the DataKeyNames to the declaration of the GridView then while
handling the SelectedindexChanged you would get that key, which you can use
to query the database programmatically, e.g.
string strKey = ((GridView)sender).SelectedDataKey.Value.ToString( );

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Jed" wrote:
I have a SqlDataSource bound to DataView control. When the selected index of
the DataView changes I would like to get the value of a field (column) from
the bound Row. The column's visible property is false. I thought I would be
able to handle the selected event of the SqlDataSource and get the Row data,
but there is nothing there.

Where are the SqlDataSourceView items? The DataView's selected item doesn't
have a DataItem, so I can't access the Row. If I show the column I want to
hide, I can access the "Text" of the GridView column, but the text has been
HtmlEncoded. (and either way of course I don't want it in the grid).

Where is the CurrentItem and can it be accessed?

Dec 6 '05 #3
I think that the SelectedIndexChanged does not rebind the Grid; it relies on
the ViewState to change the selectedRow; therefore you do not get the
DataItem associated with the SelectedRow in this event. To get a reference
to the DataItem you would have to handle some GridViewRow event such as the
RowDataBound event.

As for going back to the server to get the details of a selected item, I
would consider one of the following approaches: 1) add the value to the
DataKeyNames; that way you can retrieve uncorrupted, 2) use declarative
syntax to retrieve the details of a selected row in a detailsView instead of
programming further code based on the selectedIndex.

http://66.129.71.130/QuickStartv20/u...terDetails.src

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Jed" wrote:
Thanks for the reponse. I can't believe that I would have to call back to the
database again, but after messing with this for some time, that really does
seem to be the emerging solution.

"Phillip Williams" wrote:
You might add the DataKeyNames to the declaration of the GridView then while
handling the SelectedindexChanged you would get that key, which you can use
to query the database programmatically, e.g.
string strKey = ((GridView)sender).SelectedDataKey.Value.ToString( );

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Jed" wrote:
I have a SqlDataSource bound to DataView control. When the selected index of
the DataView changes I would like to get the value of a field (column) from
the bound Row. The column's visible property is false. I thought I would be
able to handle the selected event of the SqlDataSource and get the Row data,
but there is nothing there.

Where are the SqlDataSourceView items? The DataView's selected item doesn't
have a DataItem, so I can't access the Row. If I show the column I want to
hide, I can access the "Text" of the GridView column, but the text has been
HtmlEncoded. (and either way of course I don't want it in the grid).

Where is the CurrentItem and can it be accessed?

Dec 6 '05 #4
Jed
Hey, Phillip,

You're right. I was looking for ItemDataBound and kept passing over
RowDataBound. This problem was complicated by the fact I was not checking to
make sure the current row was a DataRow.

e.Row.RowType == DataControlRowType.DataRow

The DataItem is null on the Header and Footer rows.

Thanks for the help.

"Phillip Williams" wrote:
I think that the SelectedIndexChanged does not rebind the Grid; it relies on
the ViewState to change the selectedRow; therefore you do not get the
DataItem associated with the SelectedRow in this event. To get a reference
to the DataItem you would have to handle some GridViewRow event such as the
RowDataBound event.

As for going back to the server to get the details of a selected item, I
would consider one of the following approaches: 1) add the value to the
DataKeyNames; that way you can retrieve uncorrupted, 2) use declarative
syntax to retrieve the details of a selected row in a detailsView instead of
programming further code based on the selectedIndex.

http://66.129.71.130/QuickStartv20/u...terDetails.src

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Jed" wrote:
Thanks for the reponse. I can't believe that I would have to call back to the
database again, but after messing with this for some time, that really does
seem to be the emerging solution.

"Phillip Williams" wrote:
You might add the DataKeyNames to the declaration of the GridView then while
handling the SelectedindexChanged you would get that key, which you can use
to query the database programmatically, e.g.
string strKey = ((GridView)sender).SelectedDataKey.Value.ToString( );

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Jed" wrote:

> I have a SqlDataSource bound to DataView control. When the selected index of
> the DataView changes I would like to get the value of a field (column) from
> the bound Row. The column's visible property is false. I thought I would be
> able to handle the selected event of the SqlDataSource and get the Row data,
> but there is nothing there.
>
> Where are the SqlDataSourceView items? The DataView's selected item doesn't
> have a DataItem, so I can't access the Row. If I show the column I want to
> hide, I can access the "Text" of the GridView column, but the text has been
> HtmlEncoded. (and either way of course I don't want it in the grid).
>
> Where is the CurrentItem and can it be accessed?

Dec 6 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Martin Bischoff | last post by:
Hi, is it possible to modify the values of a SqlDataSource's select parameters in the code behind before the select command is executed? Example: I have an SqlDataSource with a...
8
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my...
3
by: zapov | last post by:
Hi! Did anyone successfully managed to use some custom ADO.NET provider with SqlDataSource? I'd like to connect to some other database than MSSQL (like MySQL, Firebird or PostgreSQL) but I'm...
3
by: adam222 | last post by:
hello, i have a web-form with a GridView control, i wanted to update & delete, using the AutoGenerateEditButton. when i used it with sqlDataSource (executing SP in the DB) it works like a...
3
by: Jim Andersen | last post by:
Just to let you know, and to help any future sorry sods who gets trapped in the same black hole...... You can't just copy/move a working sql-statement into a stored procedure. Working with a...
5
by: msch-prv | last post by:
Hi, I am trying to tie a SQLDataSource control to MySQL without success. The connection string works ok with an ObjectDataSource. (Native asp.net 2.0 MySQL dll loaded in /bin) For some reason,...
2
by: djc | last post by:
1) I am wondering if I should be using an sqlDataSource object for my particular scenario. I need to loop through a listbox and perform an INSERT sql operation for each item. Could be a few or...
2
by: Julien Sobrier | last post by:
Hello, I have 2 SqlDataSource on the same page that retrieve the same column names: <asp:SqlDataSource ID="SqlStructure" runat="server" SelectCommand="SELECT a, b FROM c WHERE d = 0 /> ...
0
by: staeri | last post by:
I have a dropdownlist attached to a SqlDataSource inside an Accordion. I receive the following error message when the SqlDataSource is inside the Accordion: "The DataSourceID of 'ddGroup' must...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.