After the SQLDataSource
gets the values from the database, I want to be able to use these values in the code behind. Kindly spare 5 minutes and give me some suggestions.
ASPX Markup:
<h2 id="pageHeader" runat="server"></h2>
<div id="pageContent" runat="server">
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:mkkConnectionString %>"
SelectCommand="SELECT [PageHeader], [PageContent] FROM [PageKeeper] WHERE ([PageName] = @PageName)">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="AboutUs" Name="PageName"
QueryStringField="Page" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
Code behind:
Public Sub loadContent(ByVal _PageName As String)
pageHeader.InnerText= "How do i get the value from SQLDatasource ??"
pageContent.InnerHtml="How do i get the value from SQLDatasource ??"
End Sub
Try this in your code behind:
DataView dview = CType(SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView)
And after, use the DataView to access the columns, if you wanna a a list:
For Each drow As DataRow In dview.Table.Rows
pageHeader.InnerText= CType(drow("PageHeader"), String)
Next drow
Or single:
pageHeader.InnerText= CType(dview.Table.Rows(0)("PageHeader"), String)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With