Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to ignore the empty cell in the GridView
    primarykey
    data
    text
    <p>I have a <code>GridView</code> and Edit link for each row. I can click on Edit and fill data in the cells of <code>GridView</code> and can Update the <code>GridView</code> row and the corresponding table in the database is also updated. </p> <p>I have a save button, which on_click reads each and every row, column by column and perform some action. </p> <p>The function works fine if all the cell in the <code>GridView</code> has some data filled in it. If the cell in the <code>GridView</code> is empty, it gives and <strong>error : Input String is not in the correct format.</strong></p> <p>The code I have tried is :</p> <pre><code>protected void SAVE_GRID_Click(object sender, EventArgs e) { foreach (GridViewRow row in GridView2.Rows) { string Loc = row.Cells[1].Text; string strg = "SELECT Location_Type FROM Quantity WHERE Locations='" + Loc + "'"; SqlCommand com = new SqlCommand(strg, con); con.Open(); SqlDataReader sdr = com.ExecuteReader(); while (sdr.Read()) { Loctype.Text = sdr[0].ToString().Trim(); } con.Close(); for (int i = 1; i &lt; GridView2.Columns.Count; i++) { String header = GridView2.Columns[i].HeaderText; string str = "SELECT Profile_Type FROM Profile_Tooltip WHERE Profile_Name='"+header+"'"; SqlCommand cmd = new SqlCommand(str,con); con.Open(); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { profiletype.Text = dr[0].ToString().Trim(); } con.Close(); if (!string.IsNullOrEmpty(row.Cells[i + 1].Text.Trim())) { int n = Convert.ToInt16(row.Cells[i + 1].Text); //int n = int.Parse(row.Cells[i].Text); for (int m = Asset_List.Items.Count - 1; m &gt;= 0; m--) { Asset_List.Items.Remove(Asset_List.Items[m]); } for (int j = 1; j &lt;= n; j++) { Asset_List.Items.Add(string.Concat(profiletype.Text, j)); } for (int k = 0; k &lt;= Asset_List.Items.Count - 1; k++) { com = new SqlCommand("INSERT INTO " + Label3.Text + " VALUES ('" + Loctype.Text + "','" + Loc + "','" + header + "','" + Asset_List.Items[k] + "')", con); con.Open(); com.ExecuteNonQuery(); con.Close(); } } } } SqlCommand comd = new SqlCommand("SELECT * FROM " + Label3.Text + "", con); SqlDataAdapter da = new SqlDataAdapter(comd); DataTable dt = new DataTable(); da.Fill(dt); GridView1.DataSource = dt; GridView1.DataBind(); } </code></pre> <p>I want to check if the cell is empty, if empty I want to increment to next cell without performing any action for the empty cell.</p> <p>Kindly help me solve this problem. Thank you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload