0

i have problem with drodownlist with multiview when i click on the button to send all the form i get this error

Server Error in '/' Application

Object reference not set to an instance of an object.

DropDown attributes

ID="DropDownList1" runat="server"   DataSourceID="SqlDataSource1"  DataTextField="Name" DataValueField="id_user"

button1_click method

protected void Button1_Click(object sender, EventArgs e)
{
    //send the message 
    authentication.userClass getuser = new authentication.userClass();

    int id_from = getuser.GetUserId(Page.User.Identity.Name.ToString());
    int id_to = Convert.ToInt32(DropDownList1.SelectedItem.Value.ToString());

    admin.ClassMessage msg = new admin.ClassMessage { Title = title.Text.ToString(), Conent = content.Text.ToString(), From_user = id_from, To_user = id_to };

    if (msg.MessageAdd(msg))
    {
        Label1.Visible = true;
        Label1.CssClass = "alert alert-success";
        Label1.Text = "message send to user " + DropDownList1.SelectedItem.Text;
    }
    else
    {
        Label1.Visible = true;
        Label1.CssClass = "alert alert-danger";
        Label1.Text = "sorry message was not send";
    }
}
Ninita
  • 1,081
  • 1
  • 16
  • 39
  • i worke with multiview and the source of page when i load – abddulrahman_ab May 04 '16 at 13:02
  • Remove unnecessary .ToString() If a variable has string type... We need more code... I can suggest DropDownList1.SelectedItem is null: check for it – Emanuele May 04 '16 at 13:07

0 Answers0