[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 238
  • Last Modified:

GridView Checkbox Value Convert to T/F?

I need to convert the standard checkbox value of true/false to T/F. I'm working on a database table with a string(1) column type. Only accepts T or F. Here's the code I have so far, still looking for more efficient way to convert.

   dr = dt.NewRow();
   dr[0] = gridView1.DataKeys[row.RowIndex]["id"].ToString();
   dr[1] = checkBox1.Checked.ToString().Replace("false", "F").Replace("true", "T");
   dt.Rows.Add(dr);

Help!
0
pointeman
Asked:
pointeman
  • 2
  • 2
1 Solution
 
Lalit ChandraCommented:
you can do

  dr[1] = checkBox1.Checked ? "T" : "F";
0
 
pointemanAuthor Commented:
Excellent!

Q. What do you call this kind of validation or string substitution called?
0
 
Lalit ChandraCommented:
This is normal c sharp  code.  This is Conditioanl/Ternary Operator.
You can know more from the below link

http://msdn.microsoft.com/en-us/library/ty67wk28.aspx

Hope this link will clear your view..
0
 
pointemanAuthor Commented:
thx
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now