Reputation: 349
Here's a picture of the gridview I'm working with: https://i.sstatic.net/Ce5gG.png
Here's my issue: I have a DropDownList (not shown in the picture) that has the same number of items as the Fraction DropDownList (shown in image). Each of the indices match with each other (ex: index 4 of the other field is the same as index 4 of the Fraction DropDownList), so when submitting the form, they have to have both of these match properly.
What I want to do is check and see if they do indeed match. I've tried:
this.gvRecords.Rows[0].Cells[2].Text
&
(((DropDownList)this.gvReserveRecords.Controls[0].Controls[0]
.FindControl("gvcbnFraction")).SelectedIndex
Neither have worked. They are just returning an empty string.
Here's some info that might help:
I am using ASP.NET Web Forms
The GridView is initially empty, but once the information is filled in, the 'Insert' LinkButton is clicked and the data is added to a database, and the GridView then calls DataBind().
I'm trying to compare the value of Fraction to a field outside of the GridView, if that matters at all.
Let me know if you need any other information!
Upvotes: 1
Views: 948
Reputation: 1660
You should be able to simply reference your DropDown control by its ID, in this case - gvcbnFraction. So, gvcbnFraction.SelectedIndex
should give the integer index and gvcbnFraction.SelectedValue
should give the string value.
If you aren't able to reference the drop down control in your code behind, then you are missing something that should be there. Possibly one of these:
protected
global::System.Web.UI.WebControls.DropDownList gvcbnFraction;
CodeBehind="MySuperAwesomePage.aspx.cs"
Inherits="MyWebApp._Default"
or something similar to that If you are using Visual Studio, you can try dragging a control from the toolbox and see if you can reference it. Doing this will automatically update your designer.cs file, eliminating #1
Upvotes: 1