c# - Dont want textbox to enter null value in datatable -


I have a data table that already has some values, as well as receiving values ​​from a text box below.

Now my problem is that when I do not enter a value in the text box that still enters the data table. I do not want to do this ..

The code can run on any machine ... any suggestions ????

thanks

  public partial class WebForm6: System.Web.UI.Page {DataTable dt; Protected Zero Page_Load (Object Sender, EventArgs E) {// Start a DataTable if (! Page.IsPostBack) {dt = New DataTable (); // Start DataColumn DataColumn myDataColumn = New DataColumn (); Start //// to add a new instance to a different column in the initial form of DataColumn with different properties. // myDataColumn = New DataColumn (); MyDataColumn.ColumnName = "firstName"; // Column's datatype property as string myDataColumn.DataType = System.Type.GetType ("System.String"); // Add and create another data column dt.Column.Add (myDataColumn); // Create a new row using the DataTable's NewRow () function // Detroit object to get a new line of data to obtain the data of myDataTable schema = dt.NewRow (); Detouro ["first name"] = "John"; // Add new data row in the data table. Dt.Rows.Add (DataRow); // Datatale similarly combines the second line in the data row = dt.NewRow (); Detroe ["first name"] = "will"; Dt.Rows.Add (DataRow); Session ["data"] = dt; GridView1.DataSource = dt; GridView1.DataBind (); }} Secure Zero btnSubmit_Click (Object Sender, EventArgs E) {If (session ["data"] == zero) {dt.Columns.Add ("FirstName"); BindtoGridViewFromTextBoxes (DT); ClearControls (); } Else {dt = (DataTable) session ["data"]; BindtoGridViewFromTextBoxes (DT); ClearControls (); }} Private Zero Clear Control () {txtName.Text = String.Empty; } Private Zero BindtoGridViewFromTextBoxes (DataTable DT) {DataRow Dr.; Dr = dt.NewRow (); Dr. ["First name"] = TCTNName. Lesson Toasting (); Dt.Rows.Add (Dr.); Session ["data"] = dt; GridView1.DataSource = dt; GridView1.DataBind (); }  

and on the .aspx page

  & lt; ASP: Gridview id = "Gridview 1" runat = "server" auto generated column = "wrong" & gt;  

& asp: TemplateField & gt; & Lt; EditItemTemplate & gt; & Lt; ASP: checkbox ID = "checkbox 1" runat = "server" /> & Lt; / EditItemTemplate & gt; & Lt; ItemTemplate & gt; & Lt; ASP: checkbox ID = "checkbox 1" runat = "server" /> & Lt; / ItemTemplate & gt; & Lt; / ASP: TemplateField & gt; & Lt; Asp: TemplateField HeaderText = "First Name" & gt; & Lt; EditItemTemplate & gt; & Lt; ASP: text box id = "text box 1" run = "server" text = '& lt;% # bind ("first name")% & gt;' & Gt; & Lt; / Asp: text box & gt; & Lt; / EditItemTemplate & gt; & Lt; ItemTemplate & gt; & Lt; ASP: label ID = "label 1" runat = "server" text = '& lt;% # bind ("first name")% & gt;' & Gt; & Lt; / ASP: Labels & gt; & Lt; / ItemTemplate & gt; & Lt; / ASP: TemplateField & gt;

Any help .... ????

Change it your way:

  Private Zero BindtoGridViewFromTextBoxes (DataTable dt ) {If (! String.IsNullOrEmptE (txtname.Text)) {DataRow dr = dt.NewRow}; Dr. ["First Name"] = TCTNName. Text; Dt.Rows.Add (Dr.); Session ["data"] = dt; } GridView1.DataSource = dt; GridView1.DataBind (); }  

Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -