sri ranjani

sri ranjani

  • NA
  • 81
  • 4.1k

How to populate dropdown value in edit mode for detailview

Jul 18 2018 7:07 AM
Hi all,
 
I've a Field site 
<asp:TemplateField HeaderText="Site" SortExpression="SITE">
<EditItemTemplate>
<asp:DropDownList ID= "TxtsiteEdit" runat="server" Text='<%# Bind("SITE") %>' AppendDataBoundItems="true" TabIndex="6">
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID= "TxtsiteInsert" runat="server" AutoPostBack="True" OnSelectedIndexChanged="sitedropdown_SelectedIndexChanged" TabIndex="6">
<asp:ListItem Text="Select Site"></asp:ListItem>
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="TxtSite" runat="server" Text='<%# Bind("SITE") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
 
I'm populating this site value using this method from another field selected index changed:
 
Private Sub Fillsite()
Dim IdtxtSiteInsert As DropDownList = CType(DetailsView3.Rows(0).FindControl("TxtsiteInsert"), DropDownList)
Dim strConn As String = WebConfigurationManager.ConnectionStrings("BMGINC_DYNAX09_ProdConnectionString").ConnectionString
Dim con As New SqlConnection(strConn)
Dim cmd As New SqlCommand()
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "Select SiteId, Name from InventSite"
Dim objDs As New DataSet()
Dim dAdapter As New SqlDataAdapter()
dAdapter.SelectCommand = cmd
con.Open()
dAdapter.Fill(objDs)
con.Close()
If objDs.Tables(0).Rows.Count > 0 Then
IdtxtSiteInsert.DataSource = objDs.Tables(0)
IdtxtSiteInsert.DataTextField = "SiteId"
IdtxtSiteInsert.DataValueField = "SiteId"
IdtxtSiteInsert.DataBind()
IdtxtSiteInsert.Items.Insert(0, "-Select-")
Else
LblError.Text = "No Site found"
End If
End Sub
 
 
i need to populate the field value  same like insert when i click edit in detailview
Thanks in advance
 
 

Answers (1)