Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

I have a contact page where there is a datalist of people and if you click on one of them you get a contact form that I want to send to that particular person.

I use sqldatasource dscontactemail to get information about that person to place on the contact form but how do I get information out of dscontactemail from the code behind for when I'm ready to send that mail?

I put a formview on the page to display the person's picture and I can get whatever I want from that dscontactemail with <%#Eval("email") for example, but how do I get that from the code behind?

I tried a hidden field but it didn't work.

Any other ways to access the SqlDataSource on a page from the code behind?

share|improve this question
    
By datasource do you mean, like repeater/data grid? – Jack Marchetti Jul 23 '09 at 5:21
    
@Spencer is completely right. Get out of the habit of using SQLDataSource etc... do not use the toolbox! for anything but UI items :) – Jack Marchetti Jul 23 '09 at 5:43

2 Answers 2

First, you really should graduate from using SqlDataSource to the classes available in the SqlClient namespace at some point so keep that in mind.

Here's the code to do it though:

DataView dview = CType(yourSqlDataSource.Select(DataSourceSelectArguments.Empty), DataView);
string str = "";

foreach(DataRow drow dview.Table.Rows)
{
    str += drow("yourcol1").ToString() + "<br />";
}
share|improve this answer
    
I agree on the graduating part. Not a fan of using DataView though. – Jack Marchetti Jul 23 '09 at 5:41
    
But there is one problem, CType is in VB not C# – Anas Naim Apr 27 '14 at 10:27

The following is more than sufficient:

dv = yourSqlDataSource.Select(DataSourceSelectArguments.Empty) as DataView;

And interrogate the DataView separately.

If intellisense does not pickup yourSqlDataSource, then simply bind it via the FindControl() of the control that has the data source:

        SqlDataSource sdsPreStartDates = (SqlDataSource)DetailsView1.FindControl("sdsPreStartDates");
        if (sdsPreStartDates != null)
        {
            DataView dv1 = (DataView)sdsPreStartDates.Select(DataSourceSelectArguments.Empty);
..
.. etc
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.