Bulleted List Master Detail with DisplayMode=LinkButton (C#)

I need to do the following: after calling a web service, the result of that call is a list. I need to display that list in a Master/Detail way using a bulleted list for the Master data and the LinkButton DisplayMode for the Detail data of each item.

With the code I currently have, I can display the Master data of the list with the Button1_click event handler, but I cannot display the details with the BulletedListMedicare_click.

when I use

LabelMedicare3.Text = supList.SupplierDatas[n].CompanyName

to access the data in the list, I get an error. This may have to do with the scope of the list, but I am new to C# so am lost.

Thanks in advance and regards.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Configuration;
using System.Data;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.Adapters;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.IO;
using System.Xml.XPath;
using System.Xml.Xsl;
using System.Net;

using InfoSoftGlobal;

public partial class Medicare : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)


    protected void Button1_Click(object sender, EventArgs e)
        medicare.MediCareSupplier mc = new medicare.MediCareSupplier();
        medicare.SupplierDataList supList;
        bool resOK;
        resOK = mc.GetSupplierByZipCode(TextBox1.Text, out supList);

        for (int i = 0; i < supList.TotalRecords; i++)



    protected void BulletedListMedicare_click(object sender,BulletedListEventArgs e)
        ListItem li = BulletedListMedicare.Items[e.Index];
        LabelMedicare1.Text = "You selected = " + li.Text + ", with value = "
            + li.Value;
        LabelMedicare2.Text = "The Index of Item you clicked: " + e.Index + "<br> The value of Item you clicked: " + BulletedListMedicare.Items[e.Index].Text;
        int n = e.Index;
LabelMedicare3.Text = supList.SupplierDatas[n].CompanyName;



Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

In your function BulletedListMedicare_click you are referencing supList which does not exist.

In the other function you defined the object supList before accessing its data. So you may just need to add this reference, but without knowing what this class is, and its constructors etc its hard to say for sure.

-> medicare.SupplierDataList supList;

May just need to add that like to your second function, so you have a reference before calling -> supList.SupplierDatas[n].CompanyName;


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.