C # create a able using the input item

Source: Internet
Author: User

Using system;
Using system. collections;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. Web;
Using system. Web. sessionstate;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. htmlcontrols;
Namespace testwebservice
{
/// <Summary>
/// Summary of webform1.
/// </Summary>
Public class webform1: system. Web. UI. Page
{
Protected system. Web. UI. webcontrols. Button button1;
Protected system. Web. UI. webcontrols. textbox textbox1;
Protected system. Web. UI. webcontrols. textbox textbox2;
Protected System. Web. UI. WebControls. TextBox TextBox3;
Protected System. Web. UI. WebControls. TextBox TextBox4;
Protected System. Web. UI. WebControls. Label Label1;
Protected System. Web. UI. WebControls. DataGrid DataGrid1;
Protected System. Web. UI. WebControls. TextBox TextBox5;
Protected System. Web. UI. WebControls. TextBox Textbox6;
Private void Page_Load (object sender, System. EventArgs e)
{
// Place user code here to initialize the page
}

# Code generated by region Web Form Designer
Override protected void OnInit (EventArgs e)
{
//
// CODEGEN: This call is required by the ASP. NET Web form designer.
//
InitializeComponent ();
Base. OnInit (e );
}

/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void InitializeComponent ()
{
This. Button1.Click + = new System. EventHandler (this. button#click );
This. Load + = new System. EventHandler (this. Page_Load );

}
# Endregion

Private void button#click (object sender, System. EventArgs e)
{

// Get the DataTable
DataTable dt = new DataTable ();
String [] aryField = {"Associate", "Fieldname", "Fileldvalue", "Operate "};
String [] aryVale = {TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text };
For (int I = 0; I <aryField. Length; I ++)
{
Dt. columns. add (new DataColumn (aryField [I], typeof (string); // set the ColumnName OF THE DataTable, and design different typeof based on different field types, it is best not to use the for loop for separate writing.
}
DataRow dr = dt. NewRow ();
For (int I = 0; I <aryField. Length; I ++)
{
Dr [aryField [I] = aryVale [I]; // you can specify the row content of a DataTable.
}
Dt. Rows. Add (dr );
// Get the DataTable end

DataGrid1.DataSource = dt;
DataGrid1.DataBind ();

Textbox6.Text = dt. Columns [0]. ColumnName;
TextBox5.Text = dt. Rows [0] ["Associate"]. ToString ();

}
}
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.