How to add record inside the table

Discussion in 'C#' started by kharearch, May 12, 2008.

  1. #1
    I want to add a record inside the table for that I am using

    'method = "post" action = "list.aspx"'

    but it is not invoking list.aspx file.

    how can I invoke list.aspx file and receive variable on list.aspx file.

    Can you please send me a sample code. Simple code, may not be for inserting record inside the table but using 'method = "post" action = ""'.

    Thanks.
     
    kharearch, May 12, 2008 IP
  2. nubsii

    nubsii Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'm not sure if this is what you want, but it uses the method/action described and writes something into a table from a variable in default.aspx.cs.

    ASPX code:
    
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Some stuff in a table</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        </div>
        </form>
    </body>
    </html>
    
    Code (markup):
    I believe the runat="" above is what will get written to html as method/action after the page is compiled+requested by a browser.

    Here's the codebehind for that page
    
    using System.Text;
    
    public partial class _Default : System.Web.UI.Page 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string[] myHypotheticalData = 
                new string[3] { 
                    "record1", 
                    "record2", 
                    "record3" 
                };
           
            StringBuilder sb = new StringBuilder();
            sb.Append("<table>\n");
            foreach (string record in myHypotheticalData)
            {
                sb.Append("<tr>\n<td>" + record + "</td>\n</tr>\n");
            }
            sb.Append("</table>\n");
    
            Label1.Text = sb.ToString();
        }
    }
    
    Code (markup):
    I created an array with 3 strings in it, I assembled them in a stringbuilder by appending the propper html markup per string, and then for simplicity I wrote the contents of my stringbuilder to a label. Realistically you would use something other than a label.
     
    nubsii, May 12, 2008 IP