Programming question in C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Duh
    New Member
    • Jul 2007
    • 6

    #1

    Programming question in C#

    Does anyone know if there is a cleaner way to do this:
    [code=asp]
    if(Boolean.Pars e(ds.Tables[0].Rows[0][6].ToString()))
    {
    rbEditActiveTru e.Checked = true;
    }
    else
    {
    rbEditActiveFal se.Checked = true;
    }

    if(Boolean.Pars e(ds.Tables[0].Rows[0][10].ToString()))
    {
    rbRoverActiveDT rue.Checked = true;
    }
    else
    {
    rbRoverActiveDF alse.Checked = true;
    }

    if(Boolean.Pars e(ds.Tables[0].Rows[0][11].ToString()))
    {
    rbRoverActiveTr ue.Checked = true;
    }
    else
    {
    rbRoverActiveFa lse.Checked = true;
    }
    [/code]
    etc, etc, etc.
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Duh.

    Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.

    I'm going to go ahead and move this thread to the .NET forum, where our resident Experts will be better able to help you out.

    Comment

    • TRScheel
      Recognized Expert Contributor
      • Apr 2007
      • 638

      #3
      How is the information for whats in the data source found? Because if you can get the row names, you could probably do it a bit cleaner.

      On a side note, you could take this:

      [code=cpp]
      if(Boolean.Pars e(ds.Tables[0].Rows[0][6].ToString()))
      {
      rbEditActiveTru e.Checked = true;
      }
      else
      {
      rbEditActiveFal se.Checked = true;
      }
      [/code]

      and turn it into:

      [code=cpp]
      rbEditActiveTru e.Checked = Boolean.Parse(d s.Tables[0].Rows[0][6].ToString());
      [/code]

      If those two are dependent on each other, setting one to true will set the other to false, and vice versa.

      Comment

      • Duh
        New Member
        • Jul 2007
        • 6

        #4
        Thanks for the help. those radio buttons are not dependent on each other. i tried that code and it writes it back to the database but when i go back to the page the selection of false does not show.


        Originally posted by TRScheel
        How is the information for whats in the data source found? Because if you can get the row names, you could probably do it a bit cleaner.

        On a side note, you could take this:

        [code=cpp]
        if(Boolean.Pars e(ds.Tables[0].Rows[0][6].ToString()))
        {
        rbEditActiveTru e.Checked = true;
        }
        else
        {
        rbEditActiveFal se.Checked = true;
        }
        [/code]

        and turn it into:

        [code=cpp]
        rbEditActiveTru e.Checked = Boolean.Parse(d s.Tables[0].Rows[0][6].ToString());
        [/code]

        If those two are dependent on each other, setting one to true will set the other to false, and vice versa.

        Comment

        • TRScheel
          Recognized Expert Contributor
          • Apr 2007
          • 638

          #5
          Then do:

          [code=cpp]
          rbEditActiveFal se.Checked = !rbEditActiveTr ue.Checked = Boolean.Parse(d s.Tables[0].Rows[0][6].ToString());
          [/code]

          Comment

          • Duh
            New Member
            • Jul 2007
            • 6

            #6
            Thanks for your help, it work.


            Originally posted by TRScheel
            Then do:

            [code=cpp]
            rbEditActiveFal se.Checked = !rbEditActiveTr ue.Checked = Boolean.Parse(d s.Tables[0].Rows[0][6].ToString());
            [/code]

            Comment

            Working...