3
Answers

create id with multiple prefix

i want different id generate as i have a combo box having different cities name and a textbox. when i choose a city from combo box then according to it city name two initial values will pick and create a id.
if i do ten entries as same city then it will generate as DE01,DE02,....DE10.
AND IF next time i choose different city then it will generate PU01,PU02,...PU08.
next time if i want again do entry using delhi city then it will check from database that how many it has previous entries then it will generate DE11,DE12,...DE16.
Next time on choose punjab it will generate PU09,PU10,...PU17.
Answers (3)
0
Ken Barrett

Ken Barrett

NA 173 0 15y
Looks as if I figured it out.  It may not be the most elegant solution, but it seems to work.. and I understand it.

By number of entries  I meant that the number of entries that are in the guest book are variable. This depends on how many people have signed it.  So the number of entries that are shown on the view guest book page depends on how many people have signed the guest book.

The way I solved this was first to include a html span on the web page. As in :
<!-- start guest book entries -->
<span id="GBentries" runat=server></span>


Then I used a data reader (I like data readers because I'm old fashioned) to load only the date, name, and comments out of the data table. There's a lot more data in there, but I only want to display these items.  As in :
  private int getGBentries() {
    int rows = 0 ;
    string cmd = "SELECT Date, Name, Comments FROM dbo.Guest" ;
    using (SqlConnection gconn = new SqlConnection(dbConn))
    {
      try {
        gconn.Open() ;
        SqlCommand Scmd = new SqlCommand(cmd, gconn);
        SqlDataReader dr = Scmd.ExecuteReader() ;
        while(dr.Read()) {
          GuestEntry ge = new GuestEntry((DateTime)dr["Date"],
                            (string)dr["Name"],(string)dr["Comments"]) ;
          entries.Push(ge) ; // build a stack to be used later
          rows++ ;
        }
        dr.Close() ;
        gconn.Close() ;
        return(rows) ;
      } catch {
        return(0) ;
      }
    }
  }


As each item was read in a string object was appended with a new html table to hold that particular entry.  As in :
  private void buildEntries() {
    foreach (GuestEntry ge in entries) {
      guestOut +=
        "<table width=800 cellpadding=8>\n" +
        "  <tr><td colspan=2><hr /></td></tr>\n" +
        "  <tr>\n" +
        "    <td width=200>Date</td>\n" +
        "    <td width=600>" + ge.getCommentDate().Date + "</td>\n" +
        "  </tr>\n" +
        "  <tr>\n" +
        "    <td width=200>Name</td>\n" +
        "    <td width=600>" + ge.getName() + "</td>\n" +
        "  </tr>\n" +
        "  <tr>\n" +
        "    <td width=200>Comments</td>\n" +
        "    <td width=600>" + ge.getComment() + "</td>\n" +
        "  </tr>\n" +
        "</table>\n" ;
    }
  }


Then the string was written out to the span id on the web page. As in :
  protected void Page_Load(object sender, EventArgs e) {
    getGBentries() ;
    buildEntries() ;
    GBentries.InnerHtml = guestOut ;
  }

0
Roei Bar

Roei Bar

NA 7.8k 0 15y
by saying number of entries, do you want the number of entries in the Guestbook or the number of entries to that page?

the number of entries in the guestbook is easy, use databindNavigator it will give you all the data you return for you to manipulate and also you can know how many entries or more truly to say how many rows you have...

for number of entries to page you need  a counter control that you can download all over