Access data from my SqlDataSource in C # .net code

I have a contact page where there is a data source, and if you click on one of them, you will receive a contact form that I want to send to this particular person.

I use sqldatasource dscontactemail to get information about this person, to post it in a contact form, but how do I get information from dscontactemail from the code behind when I am ready to send this mail?

I placed the form on the page to display the image of the person, and I can get everything I want from this dscontactemail using <% # Eval ("email"), for example, but how do I get this from the code?

I tried a hidden field, but that didn't work.

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

+3
source share
2 answers

First, you really have to stop using SqlDataSource for classes available in the SqlClient namespace at some point, so keep that in mind.

Here is the code for this:

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

foreach(DataRow drow dview.Table.Rows)
{
    str += drow("yourcol1").ToString() + "<br />";
}
+2
source

More than enough:

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

And request a DataView separately.

If intellisense does not load your SqlDataSource, just bind it using the FindControl () control that has the data source:

        SqlDataSource sdsPreStartDates = (SqlDataSource)DetailsView1.FindControl("sdsPreStartDates");
        if (sdsPreStartDates != null)
        {
            DataView dv1 = (DataView)sdsPreStartDates.Select(DataSourceSelectArguments.Empty);
..
.. etc
}
0
source

Source: https://habr.com/ru/post/1713305/


All Articles