Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8482045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:43:25+00:00 2026-06-10T19:43:25+00:00

I have a GridView and Edit link for each row. I can click on

  • 0

I have a GridView and Edit link for each row. I can click on Edit and fill data in the cells of GridView and can Update the GridView row and the corresponding table in the database is also updated.

I have a save button, which on_click reads each and every row, column by column and perform some action.

The function works fine if all the cell in the GridView has some data filled in it. If the cell in the GridView is empty, it gives and error : Input String is not in the correct format.

The code I have tried is :

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 < 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 >= 0; m--)
                    {
                        Asset_List.Items.Remove(Asset_List.Items[m]);
                    }

                    for (int j = 1; j <= n; j++)
                    {
                        Asset_List.Items.Add(string.Concat(profiletype.Text, j));
                    }

                    for (int k = 0; k <= 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();
    }

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.

Kindly help me solve this problem. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:43:26+00:00Added an answer on June 10, 2026 at 7:43 pm

    just use trim and sting function

     if (!string.IsNullOrEmpty(row.Cells[i].Text.Trim() ) ) 
    

    you need to check here

     int n = Convert.ToInt16(row.Cells[i + 1].Text); 
    

    check the string is convertible to integer or not using parse or tryparse methods of framework

    short n = 0;
    if(Int16.TryParse(row.Cells[i + 1].Text,out n);)
    {
      //perform function and user n here now
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I select all data from GridView s current row.. I have a
I have a gridview with edit and delete buttons on each row. I am
I have a table that has Edit and Delete links in each row. I
I have editable grid view, If I click on edit in any row say
I have a gridview (Edit and Delete enabled) that shows a table. A Text
I have a GridView that pulls data out of the database and populates its
i have a databound GridView in asp.net 2.0 with a row-selection link. When a
I have GridView which I can select a row. I then have a button
I have a gridview and one of the cells will show a link to
I have a gridview that is displaying data from a database using LINQ to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.