Click here to Skip to main content
15,918,889 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am trying to embed code blocks in aspx page.
as
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="abcd.aspx.vb" Inherits="abcd" %>
<%@Import Namespace="System.Data"%>
<%@Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server"> 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim connects As New SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("dbCon").ConnectionString)
        Dim sd1 As New SqlDataAdapter("STORED_PROCEDURE", connects)
        Dim ds1 As New DataTable
        sd1.Fill(ds1)
        Dim dd As String = ds1.Rows(0).Item("Type")
    End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">


Now I want to fetch the above fields returned by Procedure Inside a html table .
My question is how can I get the values and what must be the syntax to place the values in table rows.
Posted
Updated 8-Aug-12 19:35pm
v2

Take a StringBuilder take a html syntax inside that. Append each row and columns with the values returned buy the procedure. Try this:
VB
Dim s As New StringBuilder
'dt is your datatable returned by stored procedure
s.Append("<table border=1><tr>")
For Each drow As Data.DataRow In dt.Rows
    s.Append("<td>")
    s.Append(drow(0).ToString())
    s.Append("</td>")
    s.Append("<td>")
    s.Append(drow(1).ToString())
    s.Append("</td>")
    s.Append("<td>")
    s.Append(drow(2).ToString())
    s.Append("</td>")
Next
s.Append("</tr></table>")
Response.Write(s)



--Amit
 
Share this answer
 
v3
Comments
Karwa_Vivek 9-Aug-12 1:57am    
where Should I write this Code..in code behind or in aspx source page.In which event ?
_Amy 9-Aug-12 2:01am    
Wherever you are getting the datatable. This will work in both.
Karwa_Vivek 10-Aug-12 8:13am    
Thanks I got it Working
The proper way to do this is from code behind: In the design view, just double click on a blank place in your aspx and Visual Studio will create the code behind function Page_load() for you. Then, move your code there.

Doing that from within a code block is only used in other specific situations, and for backward compatibility with ASP (not NET). You should avoid that.

Best regards,

Roger Tranchez
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900