On my webpage when I edit a row from the gridview, a dropdownlist is used to select a value. Now the default selected value is the first value from the list provided by the datasource.
The problem I have is that I can't set the selected value for the DDL.
In my vb code I try to set the selected value as follows:
Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs) Handles GridView1.RowEditing
Dim row As GridViewRow
Dim lstdrop As DropDownList
row = GridView1.Rows.Item(e.NewEditIndex())
lstdrop = row.FindControl("DropDownListOwner")
lstdrop.SelectedIndex = 3
Here is a part of my asp code:
<asp:DropDownList ID="DropDownListOwner" runat="server" DataSourceID="SqlDataOwner" DataValueField="User_name" DataTextField="User_name" AutoPostBack="true">
When clicking edit on a row the following error occurs:
System.NullReferenceException: Object reference not set to an instance of an object