How to programmatically add data from sql to a listview in asp.net c# -


i trying populate listview on page. use code read data sql:

string cxnstr = system.configuration.configurationmanager.connectionstrings["connectionstring"].connectionstring;         sqlconnection conn = new sqlconnection(cxnstr);         ds = new dataset("ds");         conn.open();          sqldataadapter da = new sqldataadapter("select d.[title],d.[link],d.[description],s.[title],s.[link],s.[description] domainlinks d,supplierlinks s s.supprowid = " + supprowid + " or d.supprowid = " + supprowid, conn);             da.fill(ds);           if (ds.tables.count > 0)         {             if (ds.tables[0].rows.count > 0)             {                  lstview.datasource = ds;                  lstview.databind();              }             else             {                  lblerror.text = "there no links type";             }         } 

which goes listview:

<asp:listview id="lstview" runat="server">     <itemtemplate>         <asp:label id="titlelabel" runat="server" text='<%# eval("title") %>' />             <br />         <a href='<%#eval("link") %>' runat="server"><asp:label id="linklabel" runat="server" text='<%# eval("link") %>' /></a>             <br />         <asp:label id="descriptionlabel" runat="server" text='<%# eval("description") %>' />             <br /> </asp:listview> 

which works fine. problem other records? have no idea how add more records listview short of adding:

<asp:label id="title1label" runat="server" text='<%# eval("title1") %>' />             <br />         <a href='<%#eval("link1") %>' runat="server"><asp:label id="link1label" runat="server" text='<%# eval("link1") %>' /></a>             <br />         <asp:label id="description1label" runat="server" text='<%# eval("description1") %>' />             <br /> 

and incrementing. hard coded. how do on page load? should continue using listview? switch controls?

edit

ok. table structure both domain links , supply links:

create table [dbo].[supplierlinks]( [rowid] [int] identity(1,1) not null, [supprowid] [int] not null, [title] [varchar](250) null, [link] [varchar](max) null, [description] [varchar](max) null, primary key clustered  (     [rowid] asc )with (pad_index  = off, statistics_norecompute  = off, ignore_dup_key = off, allow_row_locks  = on, allow_page_locks  = on) on [primary] ) on [primary] 

and

create table [dbo].[domainlinks]( [rowid] [int] identity(1,1) not null, [supprowid] [int] not null, [title] [varchar](250) null, [link] [varchar](max) null, [description] [varchar](max) null, primary key clustered  (     [rowid] asc )with (pad_index  = off, statistics_norecompute  = off, ignore_dup_key = off, allow_row_locks  = on, allow_page_locks  = on) on [primary] ) on [primary] 

the parent table title , rowid inherit foreign key. in code, user selects supplier dropdownlist, id , in select statement.

sometimes, times, results more one.

hope clarifies situation

this fine now. made new page, finds foreign keys data want , title. based on these 2 variables, can draw single row out of sql.

protected void hyptit_click(object sender, eventargs e)     {         if (sender linkbutton)         {             lstart.visible = true;             linkbutton btn = (linkbutton)sender;             string buttonpressed = btn.text.tostring();             fillvals(buttonpressed);         }     }      protected void fillvals(string name)     {         string cxnstr = system.configuration.configurationmanager.connectionstrings["connectionstring"].connectionstring;         sqlconnection conn = new sqlconnection(cxnstr);         conn.open();         dataset ds;         try         {             ds = new dataset("ds");             sqldataadapter da = new sqldataadapter("select title,[description]as[article] standardreplies catrowid = " + catid + " , title '" + name + "'", conn);             da.fill(ds);             lstart.datasource = ds;             lstart.databind();         }         catch (sqlexception ex)         {             response.write(ex.tostring());         }     } 

something that. don't want give away


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -