Hi,


I am trying to create dynamic contents in a web application
where I retrieve a list of data from my database..

Let's say from table MembersInfo
And in this table it consist of
Membername,
Member Particulars,
Member Address,
file location of their photo in the server.

i do a select * from MembersInfo
How do i go about, display the data in various controls?
like the picture location as a Image, the name in a textbox and the particulars in a textbox too.

I would like to create them dynamically in which i can display all the data in the MembersInfo table.

Hope someone can help here.

<script language="vb" runat="server">
'Choose a sub, Page_Load is more known.

Sub Page_Load(ByVal S As Object, ByVal E As EventArgs)
  Dim conn As New SqlConnection( connectionstringhere )
  Dim cmdSelect As New SqlCommand( "SELECT * FROM MembersInfo", conn )
  conn.Open()
  Dim dtrReader As SqlDataReader = cmdSelect.ExecuteReader()
  
  if dtrReader.HasRows then
    'if you retrieve more than one row, you need the next line. If only one row, you can leave it out.
    'I will comment it out because you are returning only one row
    'while dtrReader.Read()
      tbLastName.Text = dtrReader("MemberName")
      tbParticulars.Text = dtrReader("MemberParticulars")
      tbAddress.Text = dtrReader("MemberAddress")
      imgPhoto.ImageURL = dtrReader("imageUrl")
    'end while
  else
    response.write("No member found for the supplied ID.")
  end if
  
  dtrReader.Close()
  conn.Close()
End Sub
</script>

This assumes that you have 4 controls on your page, 3 textbox controls and one image control. All id's are tbLastName, tbParticulars, tbAddress, and imgPhoto.

the easiest databound control to display data from database is the gridview
drag and drop a gridview to your page and take SheSaidImaPregy's datareader and bind it to your gridview as follows :

gridview1.DataSource= dtrReader;
gridview1.DataBind();

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.