Click here to Skip to main content
15,894,337 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I want to bind Aspxpopcontrol control inside of which AspxCallBackPanel present with database.I want to bind database with these elements Aspxpopcontrol and AspxCallBackPanel so that when I click on link button it will show PopUp.But Iam getting this above error.


Here is my C# code;

C#
protected void cpPopup_Callback(object source, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
  {
      //hHouse = GlobalContainer.Objects.Houses[Convert.ToString(cbPropertyList.SelectedItem.Value)];
      //bBooking = GlobalContainer.Objects.Houses[hHouse.ID].Bookings[Convert.ToString(e.Parameter)];
      bBooking = GlobalContainer.Objects.Bookings[Convert.ToString(e.Parameter)];

      lblTitle.Text = bBooking.PersonTitle;
      lblfName.Text = bBooking.fName;
      lblsName.Text = bBooking.sName;
      lblAddLine1.Text = bBooking.Address1;
      lblAddLine2.Text = bBooking.Address2;
      lblAddLine3.Text = bBooking.Address3;
      lblTown.Text = bBooking.City;
      lblCounty.Text = bBooking.County;
      lblPostCode.Text = bBooking.Postcode;
      lblState.Text = bBooking.State;
      if (lblState.Text == "")
      {
          bBooking.Country = "250";
      }
      else
      {
          bBooking.Country = "124";
      }

      if (bBooking.Country != null && bBooking.Country != "")
      {
          lblCountry.Text = NEHelperFunctions.Country.ConvertCountryCodeToName(Convert.ToInt32(bBooking.Country));
      }
      lblTelephone.Text = bBooking.Telephone;
      lblMobile.Text = bBooking.Mobile;
      lblEmail.Text = bBooking.Email;
      lblSpecialReqs.Text = bBooking.SpecialRequirements;

      lblCheckinDate.Text = bBooking.CheckinDate.ToShortDateString();
      lblCheckoutDate.Text = bBooking.CheckoutDate.ToShortDateString();
      lblPrice.Text = String.Format("{0:c}", bBooking.Price);
      lblAmtPaid.Text = String.Format("{0:c}", bBooking.AmountPaid);

      gvBookedGuests.DataSource = bBooking.BookedGuests;
      gvBookedGuests.DataBind();
  }
Posted
Comments
R-a-v-i-k-u-m-a-r 24-Feb-14 6:27am    
which line is throwing the NullReferenceException inthe code?
♥…ЯҠ…♥ 24-Feb-14 7:51am    
I think you are missing command argument value, try to fix that and try it

1 solution

Incomplete information: we need to know which line is throwing the NullReferenceException in order to tell precisely where the problem lies.

Obviously, you are using an uninitialized variable (i.e., a variable that has been declared but not initialized) and try to access one of its non-static method/property/whatever.

Solution:
- Find the line that is throwing the exception from the exception details
- In this line, check that every variable you are using has been correctly initialized (i.e., it is not null)

Good luck.

Edit: my guess is that
c#>
GlobalContainer.Objects.Bookings[Convert.ToString(e.Parameter)]

does not find any object in the collection matching the parameter => thus bBooking is null => every attempt to access a non-static member of the bBooking variable leads to a NullReferenceException.
But it's just a guess... In that case, the solution could be as simple as enclosing your code in a
C#
if (bBooking != null) {
   lblTitle.Text = bBooking.PersonTitle;
   // and so on...
}

block.
 
Share this answer
 
v5
Comments
[no name] 24-Feb-14 6:30am    
Sorry for that..But you are absolutely right Iam getting this error in

bBooking = GlobalContainer.Objects.Bookings[Convert.ToString(e.Parameter)];

please,help me how to connect with database table booking...here is my c# complete code

Booking bBooking = null;

protected void Page_Load(object sender, EventArgs e)
{

//if (!IsPostBack)
//{

// gvBookingList.Visible = false;
// cbPropertyList.DataSource = GlobalContainer.Objects.Houses;
// cbPropertyList.ValueField = "ID";
// cbPropertyList.TextField = "HouseName";
// cbPropertyList.DataBind();
//}

}

protected void cpPopup_Callback(object source, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
{
//hHouse = GlobalContainer.Objects.Houses[Convert.ToString(cbPropertyList.SelectedItem.Value)];
//bBooking = GlobalContainer.Objects.Houses[hHouse.ID].Bookings[Convert.ToString(e.Parameter)];
bBooking = GlobalContainer.Objects.Bookings[Convert.ToString(e.Parameter)];
if (bBooking != null)
{

lblTitle.Text = bBooking.PersonTitle;
lblfName.Text = bBooking.fName;
lblsName.Text = bBooking.sName;
lblAddLine1.Text = bBooking.Address1;
lblAddLine2.Text = bBooking.Address2;
lblAddLine3.Text = bBooking.Address3;
lblTown.Text = bBooking.City;
lblCounty.Text = bBooking.County;
lblPostCode.Text = bBooking.Postcode;
lblState.Text = bBooking.State;
if (lblState.Text == "")
{
bBooking.Country = "250";
}
else
{
bBooking.Country = "124";
}

if (bBooking.Country != null && bBooking.Country != "")
{
lblCountry.Text = NEHelperFunctions.Country.ConvertCountryCodeToName(Convert.ToInt32(bBooking.Country));
}
lblTelephone.Text = bBooking.Telephone;
lblMobile.Text = bBooking.Mobile;
lblEmail.Text = bBooking.Email;
lblSpecialReqs.Text = bBooking.SpecialRequirements;

lblCheckinDate.Text = bBooking.CheckinDate.ToShortDateString();
lblCheckoutDate.Text = bBooking.CheckoutDate.ToShortDateString();
lblPrice.Text = String.Format("{0:c}", bBooking.Price);
lblAmtPaid.Text = String.Format("{0:c}", bBooking.AmountPaid);

gvBookedGuests.DataSource = bBooking.BookedGuests;
gvBookedGuests.DataBind();
}
}

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