This is a migrated thread and some comments may be shown as answers.

object reference not set to an instance of an object for dropdownlist

1 Answer 207 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mohamed El-Sayed
Top achievements
Rank 1
Mohamed El-Sayed asked on 03 Mar 2013, 12:57 PM
protected void RadGrid1_ItemUpdated(object sender, GridUpdatedEventArgs e)
        {
            if (Label19.Text != null && Label18.Text != null)
            {
                System.Net.Mail.MailMessage msgMail = new System.Net.Mail.MailMessage();
 
                msgMail.Body = (" Dear  ") + "<br/>" + "<br/>" + (" Kindly Be Noted That There Is a New Request Has Been Add From : ") + Label19.Text + "<br/>" + "<br/>" + ("Kindly Check  ");
 
                msgMail.From = new MailAddress("");
 
                msgMail.To.Add(DropDownList5.SelectedItem.Attributes.ToString());
 
                msgMail.CC.Add("");
 
                msgMail.Subject = (" Your Request Had Been :  ") + Label18.Text;
 
                msgMail.IsBodyHtml = true;
 
                SmtpClient smtp = new SmtpClient("");
 
                smtp.UseDefaultCredentials = false;
 
                NetworkCredential crdntl = new NetworkCredential("");
 
                smtp.Credentials = crdntl;
 
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
 
                smtp.Send(msgMail);
 
            }

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 04 Mar 2013, 05:01 AM
Hello,

if (DropDownList5 != null)
        {
            if (DropDownList5.SelectedItem != null)
            {
                if (DropDownList5.SelectedItem.Attributes != null && DropDownList5.SelectedItem.Attributes.Count > 0)
                {
                    string str = Convert.ToString(DropDownList5.SelectedItem.Attributes);
                    // Access your attribute here
                }
                else
                {
                    // Attribute not found
                }
            }
            else
            {
                // Selected item not found. but some text in dropdownlist
                string str = DropDownList5.Text;
            }
        }
        else
        {
            // Dropdown not found
        }


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Mohamed El-Sayed
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or