c# - Displaying specific information on aspx page using database -


i building website asp.net web forms, , sql database.

on 1 particular page have number of houses informations.
there 571 houses in total.
when click on particular house, want bring new page more information house.
data coming table in database.

is there way of knowing house has been selected, , display data on new aspx page house?

i know create many separate aspx pages each house there 571 houses , there have 571 aspx pages. far wasted code.
when click on house name want 1 aspx page want know have selected house , display information specific one. accessing database information house , displays it.

the main obstacle here knowing house has been selected. know how display information database.

houses.aspx

enter image description here

when click house name want display page 1 below.

houseinfo.aspx

enter image description here

houseinfo.aspx.cs

using (sqlconnection connection = new sqlconnection(configurationmanager.connectionstrings["connectionstring"].connectionstring))             {                 using (sqlcommand command = new sqlcommand("select id, name, townland, near, status, built, description, families houses order name desc", connection))                 {                     connection.open();                     using (sqldatareader reader = command.executereader())                     {                         while (reader.read())                         {                             lblid.text = reader[0].tostring();                             lblname.text = reader[1].tostring();                             lbltown.text = reader[2].tostring();                             lblnear.text = reader[3].tostring();                             lblstatus.text = reader[4].tostring();                             lblbuilt.text = reader[5].tostring();                             lbldesc.text = reader[6].tostring();                             lblfam.text = reader[7].tostring();                         }                     }                 }             }            } 

this how accessing database display of info on houseinfo page already.

houseinfo.aspx

<b>id:</b> <asp:label id="lblid" runat="server"></asp:label> <br /><b>name of house:</b> <asp:label id="lblname" runat="server"></asp:label> <br /><b>townland:</b> <asp:label id="lbltown" runat="server"></asp:label> <br /><b>near:</b> <asp:label id="lblnear" runat="server"></asp:label> <br /><b>status/public access:</b> <asp:label id="lblstatus" runat="server </asp:label> <br /><b>date built:</b> <asp:label id="lblbuilt" runat="server"></asp:label> <br /><b>description:</b> <asp:label id="lbldesc" runat="server"></asp:label> <br /><b>associated families:</b> <asp:label id="lblfam" runat="server"></asp:label> 

houses.aspx

<%@ page title="houses" language="c#" masterpagefile="~/master.master" autoeventwireup="true" codebehind="houses.aspx.cs" inherits="houses_of_mayo.images.houses" enableeventvalidation="false" %>  <asp:content id="content1" contentplaceholderid="contentplaceholder1" runat="server">      <script>         $(function () { setcurrenttab('tab2'); });     </script>     <div class="box">         <div>             <div class="body">                 <h1>houses</h1>                  <ul id="rooms">                     <asp:repeater id="rptdata" runat="server" >                         <itemtemplate>                             <li>                                 <a href="houseinfo.aspx">                                     <img src="x" alt="img" /></a>                                 <h2>                                     <a href="houseinfo.aspx"><asp:label runat="server" text='<%# eval("name") %>'></asp:label></a></h2>                                 <p>                                     <b>id: </b>                                     <asp:label runat="server" text='<%# eval("id") %>'></asp:label>                                     <br />                                     <b>name of house: </b>                                     <asp:label runat="server" text='<%# eval("name") %>'></asp:label>                                     <br />                                     <b>townland: </b>                                     <asp:label runat="server" text='<%# eval("townland") %>'></asp:label>                                     <br />                                     <b>near: </b>                                     <asp:label runat="server" text='<%# eval("near") %>'></asp:label>                                     <br />                                     <b>status/public access: </b>                                     <asp:label runat="server" text='<%# eval("status") %>'></asp:label>                                     <br />                                      <b>date built: </b>                                     <asp:label runat="server" text='<%# eval("built") %>'></asp:label>                                 </p>                             </li>                         </itemtemplate>                     </asp:repeater>                 </ul>                 <asp:repeater id="rptpager" runat="server">     <itemtemplate>         <asp:linkbutton id="lnkpage" runat="server" text='<%#eval("text") %>' commandargument='<%# eval("value") %>'             style="padding:8px; margin:2px; background:#ac9e94; border:solid 1px #666; font:8pt; color:#594334; display: inline-block;"             cssclass='<%# convert.toboolean(eval("enabled")) ? "page_enabled" : "page_disabled" %>'             onclick="page_changed" onclientclick='<%# !convert.toboolean(eval("enabled")) ? "return false;" : "" %>'></asp:linkbutton>    </itemtemplate> </asp:repeater>             </div>         </div>       </div> </asp:content> 

houses.aspx.cs

private int pagesize = 5;          protected void page_load(object sender, eventargs e)         {             if (!ispostback)             {                 this.getcustomerspagewise(1);             }         }          private void getcustomerspagewise(int pageindex)         {             string constring = configurationmanager.connectionstrings["connectionstring"].connectionstring;             using (sqlconnection con = new sqlconnection(constring))             {                 using (sqlcommand cmd = new sqlcommand("gethousespagewise", con))                 {                     cmd.commandtype = commandtype.storedprocedure;                     cmd.parameters.addwithvalue("@pageindex", pageindex);                     cmd.parameters.addwithvalue("@pagesize", pagesize);                     cmd.parameters.add("@recordcount", sqldbtype.int, 4);                     cmd.parameters["@recordcount"].direction = parameterdirection.output;                     con.open();                     idatareader idr = cmd.executereader();                     rptdata.datasource = idr;                     rptdata.databind();                     idr.close();                     con.close();                     int recordcount = convert.toint32(cmd.parameters["@recordcount"].value);                     this.populatepager(recordcount, pageindex);                 }             }         }          private void populatepager(int recordcount, int currentpage)          {             double dblpagecount = (double)((decimal)recordcount / convert.todecimal(pagesize));             int pagecount = (int)math.ceiling(dblpagecount);             list<listitem> pages = new list<listitem>();             if (pagecount > 0)             {                 (int = 1; <= pagecount; i++)                 {                     pages.add(new listitem(i.tostring(), i.tostring(), != currentpage));                 }             }             rptpager.datasource = pages;             rptpager.databind();         }          protected void page_changed(object sender, eventargs e)         {             int pageindex = int.parse((sender linkbutton).commandargument);             this.getcustomerspagewise(pageindex);         } 

map (houseinfo.aspx)

enter image description here

houseinfo.aspx

<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>     <script>         function initialize() {             var mylatlng = new google.maps.latlng(53.613873, -9.668301);             var mapoptions = {                 zoom: 17,                 center: mylatlng             }             var map = new google.maps.map(document.getelementbyid('map-canvas'), mapoptions);              var contentstring = '<div id="content">' +                                   '<div id="sitenotice">' +                                   '</div>' +                                   '<h2 id="firstheading" class="firstheading">aasleagh lodge</h2>' +                                   '<div id="bodycontent">' +                                   '<b>id:</b> a1' +                                   '</br><b>name:</b> aasleagh lodge' +                                   '</br><b>townland:</b> srahatloe' +                                   '</br><b>ref:</b> 1' +                                   '</br><b>latitude:</b> 53.613873' +                                   '</br><b>longitude:</b> -9.668301' +                                   '</div>' +                                   '</div>';              var infowindow = new google.maps.infowindow({                 content: contentstring             });              var image = 'images/icon56.png';             var marker = new google.maps.marker({                 position: mylatlng,                 map: map,                 title: 'aasleagh lodge',                 icon: image             });             google.maps.event.addlistener(marker, 'click', function () {                 infowindow.open(map, marker);             });         }          google.maps.event.adddomlistener(window, 'load', initialize); 

houseinfo table

[id]       char (10)      not null,     [name]     nvarchar (max) null,     [townland] nvarchar (max) null,     [ref]      int            null,     [lat]      float (53)     null,     [lng]      float (53)     null,     constraint [pk_houseinfo] primary key clustered ([id] asc) 

in code sending id of house other page.

<a href='<%# "houseinfo.aspx?houseid=" + eval("id").tostring() %>'>                     <img src="x" alt="img" /></a> 

and here getting id

string houseid = request.params["houseid"].tostring(); 

also in here filtering data houses information

"select id, name, townland, near, status, built, description, families houses id = '" + houseid + "' order name desc" 

complete code ;

houseinfo.aspx.cs

string houseid = request.params["houseid"].tostring();  using (sqlconnection connection = new sqlconnection(configurationmanager.connectionstrings["connectionstring"].connectionstring)) {     using (sqlcommand command = new sqlcommand("select id, name, townland, near, status, built, description, families houses id = '" + houseid + "' order name desc", connection))     {          connection.open();          using (sqldatareader reader = command.executereader())          {               while (reader.read())               {                   lblid.text = reader[0].tostring();                   lblname.text = reader[1].tostring();                   lbltown.text = reader[2].tostring();                   lblnear.text = reader[3].tostring();                   lblstatus.text = reader[4].tostring();                   lblbuilt.text = reader[5].tostring();                   lbldesc.text = reader[6].tostring();                   lblfam.text = reader[7].tostring();               }          }     } }    

houses.aspx

<ul id="rooms">     <asp:repeater id="rptdata" runat="server" >         <itemtemplate>             <li>                 <a href='<%# "houseinfo.aspx?houseid=" + eval("id").tostring() %>'>                 <img src="x" alt="img" /></a>                 <h2>                 <a href='<%# "houseinfo.aspx?houseid=" + eval("id").tostring() %>'><asp:label runat="server" text='<%# eval("name") %>'></asp:label></a></h2>                  <p>                  <b>id: </b>                  <asp:label runat="server" text='<%# eval("id") %>'></asp:label>                  <br />                  <b>name of house: </b>                  <asp:label runat="server" text='<%# eval("name") %>'></asp:label>                  <br />                  <b>townland: </b>                  <asp:label runat="server" text='<%# eval("townland") %>'></asp:label>                  <br />                  <b>near: </b>                  <asp:label runat="server" text='<%# eval("near") %>'></asp:label>                  <br />                  <b>status/public access: </b>                  <asp:label runat="server" text='<%# eval("status") %>'></asp:label>                  <br />                   <b>date built: </b>                  <asp:label runat="server" text='<%# eval("built") %>'></asp:label>                  </p>              </li>         </itemtemplate>     </asp:repeater> </ul> 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -