Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

a call to bind was not well formed ?

Posted on 2009-05-14
12
Medium Priority
?
1,081 Views
Last Modified: 2013-11-08
I am trying to set the value  of a date when it is null from a different control but I get the following error : a call to bind was not well formed

-- error with this because of the conditional statement 
    <telerik:RadDatePicker  ID="radBillPeriodStartDate1" Skin="Office2007" Style="vertical-align: middle;"
                            runat="server" 
                            DbSelectedDate='<%# Bind("END_BILLING_PERIOD","{0:D}") == DBNull.Value ? radBillPeriodEndDate.SelectedDate : Bind("END_BILLING_PERIOD","{0:D}") %>'
                            >
                    
-- this works fine when there is no conditional statement 
 
     <telerik:RadDatePicker ID="radBillPeriodEndDate1"  Skin="Office2007" Style="vertical-align: middle;"
                            runat="server" DbSelectedDate='<%# Bind("END_BILLING_PERIOD", "{0:d}") %>'
                            >

Open in new window

0
Comment
Question by:tech_question
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 27

Assisted Solution

by:nmarun
nmarun earned 2000 total points
ID: 24388945
See what happens when you try something like this:

    <telerik:RadDatePicker  ID="radBillPeriodStartDate1" Skin="Office2007" Style="vertical-align: middle;"
                            runat="server"
                            DbSelectedDate='<%# GetDateValue(Bind("END_BILLING_PERIOD","{0:D}").ToString()) %>'
                            >
and in the code-behind:

public DateTime GetDateValue(string endBillingPeriod)
{
      DateTime retValue;
      if(endBillingPeriod == null)
      {
           retValue = radBillPeriodEndDate.SelectedDate;
      }
      else
      {
            retValue = DateTime.Parse(endBillingPeriod);
       }
}
0
 

Author Comment

by:tech_question
ID: 24389169
I changed it, I had to change the method type to protected but now it tells me CS0103: The name 'Bind' does not exist in the current context
0
 
LVL 27

Expert Comment

by:nmarun
ID: 24390565
Try using Eval:

  <telerik:RadDatePicker  ID="radBillPeriodStartDate1" Skin="Office2007" Style="vertical-align: middle;" runat="server"
                            DbSelectedDate='<%# GetDateValue(Eval("END_BILLING_PERIOD","{0:D}").ToString()) %>' >
0
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 

Author Comment

by:tech_question
ID: 24396301
I did this and it seems to work but now the problem is in add mode, when I insert an item , the value associated to it is null  - is there anything that I can try ?

DbSelectedDate='<%#GetDateValue(Convert.ToDateTime(DataBinder.Eval(Container.DataItem, "BEGIN_BILLING_PERIOD")))%>'
protected DateTime GetDateValue(DateTime d)
    {
        DateTime retValue;
        if (d == null)
        {
            retValue = DateTime.Parse(radBillPeriodEndDate.SelectedDate.ToString());
        }
        else
        {
            retValue = d;
            //Convert.ToDateTime(d, "{0:d}");
        }
        return retValue;
    }

Open in new window

0
 
LVL 27

Expert Comment

by:nmarun
ID: 24397371
What do you mean by:
the value associated to it is null

What is 'it' here? Is it the radBillPeriodEndDate control?
0
 

Author Comment

by:tech_question
ID: 24397741
it is the objectdatasource parameter that is bound to this control which is begin_billing_period.

  <asp:Parameter Name="BEGIN_BILLING_PERIOD" Type="DateTime" />
     
   <telerik:GridTemplateColumn HeaderText="Billing Period Start Date" UniqueName="BEGIN_BILLING_PERIOD"
                    EditFormColumnIndex="1">
                    <HeaderStyle Width="62px" />
                    <ItemTemplate>
                        <asp:Label runat="server" ID="lblBillingPeriodStartDate" Text='<%# Eval("BEGIN_BILLING_PERIOD", "{0:D}") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadDatePicker  ID="radBillPeriodStartDate1" Skin="Office2007" Style="vertical-align: middle;"
                            runat="server"  DbSelectedDate='<%#GetDateValue(Convert.ToDateTime(DataBinder.Eval(Container.DataItem, "BEGIN_BILLING_PERIOD")))%>' 
                            MinDate='<%# DateTime.Now.AddMonths(Convert.ToInt32(ConfigurationManager.AppSettings["BillingMin"].ToString()))%>'
                            MaxDate='<%# DateTime.Now.AddMonths(Convert.ToInt32(ConfigurationManager.AppSettings["BillingMax"].ToString()))%>'
                            >
                        <Calendar ShowRowHeaders="false" />
                        </telerik:RadDatePicker>
                        <asp:RequiredFieldValidator ID="rfvBillPeriodstartDate" runat="server" ControlToValidate="radBillPeriodStartDate1"
                            ErrorMessage="Billing Period Start Date must be within the range of 18 months in the past or 2 months in the future">*</asp:RequiredFieldValidator>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
             

Open in new window

0
 
LVL 27

Expert Comment

by:nmarun
ID: 24400322
So what line is causing the break?
0
 

Author Comment

by:tech_question
ID: 24400921
when I add a record, by default it picks up the calendar control's date which is perfect but then it is unable to bind the value to the object datasource parameter (end_billing_period) , which by default takes it as null (which is 01/01/0001 for a datetime value). when I hit save , the value that is going to the database is 01/01/0001 not the value entered by the user. Does it makes sense ?
0
 
LVL 27

Accepted Solution

by:
nmarun earned 2000 total points
ID: 24403102
0
 

Author Comment

by:tech_question
ID: 24412759
thanks for pointing that article out. I looked at the article, it does not address my issue. If you look at the
code below      d = Convert.ToDateTime(radBillPeriodEndDate.SelectedDate); (I am not binding this value to the data. Is there any way to do this    
// DataBinder.Eval(dataItem, "BEGIN_BILLING_PERIOD") = radBillPeriodEndDate; ?
       
    protected DateTime GetDateString(object dataItem)
    {
        DateTime d ;
        
        if (DataBinder.Eval(dataItem, "BEGIN_BILLING_PERIOD") == DBNull.Value)
        {
           // DataBinder.Eval(dataItem, "BEGIN_BILLING_PERIOD") = radBillPeriodEndDate;
            d = Convert.ToDateTime(radBillPeriodEndDate.SelectedDate);
        }
 
        else
        {
            d = Convert.ToDateTime(DataBinder.Eval(dataItem, "BEGIN_BILLING_PERIOD"));
            
        }
        
        return d;
    }

Open in new window

0
 
LVL 27

Expert Comment

by:nmarun
ID: 24414517
tech_questions,

I'm kinda lost of in this issue. Here's is where I stand right know:

When you add new record to your database, you are not entering a date value to the end billing date field. So when you are binding it to the gridview, it is showing 01/01/0001 date and you want to know if there is a way out of this. Am I right? If not, please provide details.
0
 

Author Comment

by:tech_question
ID: 24422360
thanks for the link, I did the below for one of those articles and it works like a champ. Thank you.
 protected void gridInvLines_ItemCommand(object source, GridCommandEventArgs e)
    {
        
            switch (e.CommandName)
            {
 
                case RadGrid.InitInsertCommandName:
                    e.Canceled = true;
 
                    //this is for the Calendar Date control
                    System.Collections.Specialized.ListDictionary newValues = new System.Collections.Specialized.ListDictionary();
 
                    if(radBillPeriodStartDate.SelectedDate.HasValue)
                          newValues["BEGIN_BILLING_PERIOD"] = Convert.ToDateTime(radBillPeriodStartDate.SelectedDate);
                    if(radBillPeriodEndDate.SelectedDate.HasValue)
                          newValues["END_BILLING_PERIOD"]   = Convert.ToDateTime(radBillPeriodEndDate.SelectedDate);
 
                    e.Item.OwnerTableView.InsertItem(newValues);
 
                    break;
 
                default:
 
                    break;
        }
    }

Open in new window

0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question