[RESOLVED] Help needed with getting an unspecified amount of data

Hiya,

I am a fairly new developer with ASP.NET so apologies if this is in the wrong forum.

I am creating a booking system which takes the number of people on the and stores it into a database table. I then need to store specific data about each person on the trip, name, contact number etc. The idea is that once they have specified the amount of people (looking at a max of 8 per trip probably) they get greated with a page requesting the details, with the numbers parsed as a query string. What would be the best way to do it, and how? 

I investigated using a HTML table but this looked untidy and would rather use something like a repeater, but wouldn't know how to start with using a repeater with a query string.

Thanks in advance!

Dear StereoRoyal,

Based on your requirement i would create a user control which contains the specific data about each person (trip, name, contact number, etc) and depending upon the number which is sent as query string/session variable from the other page, i would loop this user control to load as wizard control for that many times with status of the number of people inserted after each loop.

If you find this way suitable, please follow this and ask me for more clarification. 

Create Repeater control on ASPX page as shown in below sample code:

<asp:Repeater runat="server" ID="myRepeater" >
            <HeaderTemplate>
                <table width="90%" align="center" border="1">
                    <tr>
                        <th>Category</th>
                        <th>Gender</th>
                        <th>No_Of_Files</th>
                        <th>QueryString Value</th>
                    </tr>
            </HeaderTemplate>
            <ItemTemplate>
                <tr>
                    <td><%# DataBinder.Eval(Container, "DataItem.Category")%></td>
                    <td><%# DataBinder.Eval(Container, "DataItem.Gender")%></td>
                    <td><%# DataBinder.Eval(Container, "DataItem.No_Of_Files")%></td>
                    <td>The QueryString value is <%=Request.QueryString["my_querystring_parameter"] %></td>
                </tr>
            </ItemTemplate>
            <FooterTemplate>
                </table>
            </FooterTemplate>
        </asp:Repeater>

In th CS file:

    protected void Page_Load(object sender, EventArgs e)
    {
        DataTable objDT = new DataTable();

        objDT.Columns.Add("Category");
        objDT.Columns.Add("Gender");
        objDT.Columns.Add("No_Of_Files");

        objDT.Rows.Add("Indian", "M", "2");
        objDT.Rows.Add("American", "F", "5");
        objDT.Rows.Add("American", "M", "4");
        objDT.Rows.Add("Indian", "F", "3");

        myRepeater.DataSource = objDT;
        myRepeater.DataBind();
    }

Now run the application. In the browser, pass QueryString to your page as:

http://~/your_page.aspx?my_querystring_parameter='My Value'

What say for Inline Create/Edit light Weight Grid using JQuery - http://www.trirand.com/blog/ 

Create the number of rows which you get in query string, then fill in the details in the jquery grid...

The reason why I am recommending this grid was, large data entry can be easy with simple and quick inline grid...you can quickly navigate through the cells using TAB button of keyboard...

Thanks, 

Having created my user control, I am now getting it to display on screen. 

This is my user control:

<table class="style1">
<tr>
<td class="style2" width="50">
<asp:Label ID="Label1" runat="server" Text="Adult Name"></asp:Label>
</td>
<td width="50">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
</table>

And this is how I am adding the control to the wizard:


protected void Page_Load(object sender, EventArgs e)
    {
       for (int i = 0; i < 5; i++)
        {
            WizardStepBase newStep = new WizardStep();
            GetAdultData adults = new GetAdultData();
            newStep.Controls.Add(adults);
            Wizard1.WizardSteps.Add(newStep);
        }
}
Yet it is not displaying properly. 

I prefer to go for a Javascript functions where create the rows dynamically and you always have option to save the values to the DB.

Here is the javascript code

-------

function

addRow(tableID) {

var

table = document.getElementById(tableID);

var rowCount = document.getElementById('MainContent_txtNoOfPersons'

);

if

(rowCount.value <= 0) {

alert(

"Please Enter No. Of Passengers to be Added@!"

);

return false

;

}

//delete all rows and then insert again

var

rows = table.rows.length;

for (var

i = rows; i > 0; i--) {

table.deleteRow(i-1);

}

for

(i = 0; i < rowCount.value; i++) {

var

row = table.insertRow(i);

var

cell1 = row.insertCell(0);

var element1 = document.createElement("input"

);

element1.type =

"checkbox"

;

cell1.appendChild(element1);

var

cell2 = row.insertCell(1);

cell2.innerHTML = i + 1;

var

cell3 = row.insertCell(2);

var element2 = document.createElement(<span style="font-family: Consolas; color: #800000; font-size: x-small;" face="Consolas" size="2" col

I prefer to go for a Javascript functions where create the rows dynamically and you always have option to save the values to the DB.

Here is the javascript code

-------

function

addRow(tableID) {

var

table = document.getElementById(tableID);

var rowCount = document.getElementById('MainContent_txtNoOfPersons'

);

if

(rowCount.value <= 0) {

alert(

"Please Enter No. Of Passengers to be Added@!"

);

return false

;

}

//delete all rows and then insert again

var

rows = table.rows.length;

for (var

i = rows; i > 0; i--) {

table.deleteRow(i-1);

}

for

(i = 0; i < rowCount.value; i++) {

var

row = table.insertRow(i);

var

cell1 = row.insertCell(0);

var element1 = document.createElement("input"

);

element1.type =

"checkbox"

;

cell1.appendChild(element1);

var

cell2 = row.insertCell(1);

cell2.innerHTML = i + 1;

var

cell3 = row.insertCell(2);

var element2 = document.createElement("input"

);

element2.type =

"text"

;

cell3.appendChild(element2);

}

return false

;

}

----------------

HTML Code

-------------

<asp:Label ID="lblNoOfPersons" Text="No.Of Passengers" runat="server"></asp:Label

>

<asp:TextBox ID="txtNoOfPersons" runat="server"></asp:TextBox>&nbsp;<asp:Button ID="btnGenerate" runat="server" Text="Generate Table" OnClientClick="javascript:addRow('tblPassengerDetails'); return false;"

/>

<table id

='tblPassengerDetails'>

</table

>

-------------

Let me know if that solves the problem.

Hi everyone,

Thanks for all your help. The solution I have come up with is to use 2 placeholders for the two types of guest and simply add the controls using a For loop depending on how many are required. I can then get the data using the FindControl command.

thoughts on "[RESOLVED] Help needed with getting an unspecified amount of data"

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>