Results 1 to 3 of 3

Thread: Setting default value when binding in formview?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2000
    Posts
    1,463

    Question Setting default value when binding in formview?

    Hi Everyone,

    Below is a line I have in my ItemTemplate of a FormView. The value in the table is null rather than true/false. Is there any way I can set the default for this to be false if it is null? Or can I do this in my stored procedure in the Select statement to return false if null?

    Code:
    <asp:CheckBox ID="chkCharges" runat="server" Checked='<&#37;# Bind("MCOverrideCharges") %>' 
           Text="Yes" Enabled = "False" />
    Thanks!

  2. #2
    Hyperactive Member dnanetwork's Avatar
    Join Date
    Oct 2007
    Location
    Mumbai
    Posts
    349

    Re: Setting default value when binding in formview?

    nope, DataBound is the only way 2 Go through and there is one more ...which we can try later...

    try this code..

    hope it should work for you

    Code:
     
    
    void ProductFormView_DataBound(Object sender, EventArgs e)
      {
    
        // To prevent the user from adding duplicate items, 
    
        // Use the Row property to retrieve the data row.
        FormViewRow row = ProductFormView.Row;
    
       CheckBox chk = (CheckBox)row.FindControl("chkCharges");
    
       string check = chk.Checked;
    
      if(check == null || check == "")
          chk.Checked = false;
    }
    Hope that helps.
    Last edited by dnanetwork; Mar 12th, 2010 at 10:46 AM. Reason: Previous code was Gridview Code...

  3. #3
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Setting default value when binding in formview?

    Hey,

    I think you might have missed what the OP is referring to.

    Warren, are you saying that you are getting a null back from the database, and you want to "convert" that to a false, and set the CheckBox accordingly?

    If so, I would be more inclined to fix this at the database level. Don't let them write a null into that field in the database, always default it to false.

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width