Click here to Skip to main content
15,901,373 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends....
I want to define datatype of gridview column. If data is not matching in gridview according to column datatype then I want that cell in red color and editable. If there is any solution then give me advice how can I handel this.
Posted
Comments
Mayur Panchal 24-May-13 3:22am    
Is it winform or web(asp.net)??
Richard MacCutchan 24-May-13 3:31am    
Look at some of the events for gridview columns and check the data when an event fires.

1 solution

Below is the code just to give you an idea. I hope it will help.

C#
protected void Page_Load(object sender, EventArgs e)
      {
          object[] dataSource = { "Cell 1", 1, 2 };
          GridView1.DataSource = dataSource;
          GridView1.DataBind();
      }

      protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
      {
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              if (e.Row.DataItem.GetType() == typeof(Int32))
              {
                  TextBox txt = new TextBox();
                  txt.Text = e.Row.Cells[0].Text;
                  e.Row.Cells[0].Text = "";
                  e.Row.Cells[0].BackColor = System.Drawing.Color.Red;
                  e.Row.Cells[0].Controls.Add(txt);
              }
          }
      }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900