Advertisement

02.21.2008 at 01:12PM PST, ID: 23182652
[x]
Attachment Details

DropDownList pre-selection on GridView Edit

Asked by SeTech in Programming for ASP.NET, C# Programming Language, Visual Studio .NET 2005

Tags: C#

I have a GridView in which one column normally contains a Label. To insert a new row into the Gridview (well, technically, the database the GridView displays data from), the value for that column is chosen from a DropDownList bound to an XML file (at runtime in the C# code-behind).

On a user clicking the "Edit" command, the Edit template for that column is another DropDownList to ensure that the input data is valid. However, I need that DropDownList to be pre-selected with the value that already exists in the label. But obviously, my methodology is incorrect, and I'm quite frankly lost on this. I'm getting an error message of "Object reference not set to an instance of an object". I'll post the method below.

What am I doing wrong, and how can I do it right?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
protected void gvResult_RowEditing(object sender, GridViewEditEventArgs e)
    {
        ds = new DataSet();
        ServerPath = Server.MapPath(@"\");
        ds.ReadXml(ServerPath + @"\Library\xml\claimdir\Office.xml");
        DropDownList ddl = (DropDownList)(gvResult.Rows[e.NewEditIndex].FindControl("ddlOfficeUpdate"));
        ddl.DataTextField = "Text";
        ddl.DataValueField = "Value";
        ddl.DataSource = ds.Tables[0];
        ddl.DataBind();
        ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByValue(((Label)(gvResult.Rows[e.NewEditIndex].FindControl("lblOffice"))).Text));
    }
[+][-]02.21.2008 at 01:37PM PST, ID: 20952114

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.21.2008 at 09:34PM PST, ID: 20954919

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.22.2008 at 06:37AM PST, ID: 20957632

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.22.2008 at 08:41PM PST, ID: 20963698

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.25.2008 at 08:31AM PST, ID: 20976876

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.25.2008 at 12:55PM PST, ID: 20979133

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.25.2008 at 09:47PM PST, ID: 20981906

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.26.2008 at 05:17AM PST, ID: 20983932

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.26.2008 at 08:19PM PST, ID: 20991330

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.27.2008 at 07:55AM PST, ID: 20994999

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.27.2008 at 10:26PM PST, ID: 21001600

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.28.2008 at 07:29AM PST, ID: 21004644

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.29.2008 at 08:48PM PST, ID: 21020006

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Programming for ASP.NET, C# Programming Language, Visual Studio .NET 2005
Tags: C#
Sign Up Now!
Solution Provided By: digitalZo
Participating Experts: 2
Solution Grade: B
 
 
[+][-]03.10.2008 at 07:24AM PDT, ID: 21086593

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.01.2008 at 12:52AM PDT, ID: 21252007

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]04.01.2008 at 06:07AM PDT, ID: 21253470

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.05.2008 at 06:20AM PDT, ID: 21288044

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]04.07.2008 at 05:57AM PDT, ID: 21296374

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.06.2008 at 12:53PM PDT, ID: 21510435

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628