farmkitty 0 Newbie Poster

Hi everyone and thanks for reading my post. I have a gridview that had a field called "GenericNameHepDrug" within the row. It's not the key field. I have an insert button that opens a formview in insertmode. How can I get the selected value of generichepdrug into the formview that opens when the button is clicked? I am using VB.NET 2.0.

Here's some code from Gridview1 (GenericNameHepDrug is the field I want to be selected in the Formview DropDownList:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" DataKeyNames="RxOrdID" Caption="Select from the Medication Orders" CssClass="GridViewPrettyReg" AlternatingRowStyle-BackColor="#fffecc" RowStyle-BackColor="#ffffff"    
        DataSourceID="sqlMedOrdSelector" Width="750px" AutoGenerateColumns="False" PageSize="5">   
        <Columns>   
            <asp:CommandField SelectText="view" ShowSelectButton="True" ButtonType="Button">   
                <ControlStyle CssClass="ButtonSelect" />   
            </asp:CommandField>   
            <asp:BoundField DataField="GenericNameHepDrug" HeaderText="Drug/Medication" SortExpression="GenericNameHepDrug" />        
            <asp:BoundField DataField="HepDrugMapGroup"  HeaderText="Mapping Group" SortExpression="HepDrugMapGroup" />   
            <asp:BoundField DataField="DateRxWritten" DataFormatString="{0:d}" HtmlEncode="False" HeaderText="Date Rx Written" SortExpression="DateRxWritten"/>   
        </Columns>

Here is what I tried to do in the code nehind of the button3_click:

Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click   
        
   If Me.FormView1.CurrentMode = FormViewMode.Insert Then   
  
            Dim ddl As DropDownList = CType(Me.GridView1.FindControl("DropDownList6"), DropDownList)   
            If ddl IsNot Nothing Then   
                ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByText("GenericNameHepDrug"))   
                Dim ddl2 As DropDownList = CType(Me.FormView1.FindControl("DropDownList6"), DropDownList)   
                ddl2.Text = ddl.Text   
  
            End If   
  
    End Sub

Finally, here's some code from FormView1 where I want the dropdownlist (dropdownlist6) to have the value from the gridview GenericnameHepDrug field preselected in dropdownlist6:

<asp:DropDownList ID="DropDownList6" Enabled="false" AutoPostBack="true" runat="server" DataSourceID="SqlluHepMeds" CssClass="DropDownListPretty" 
                            DataTextField="GenericNameHepDrug" OnSelectedIndexChanged="DropDownList6_SelectedIndexChanged" DataValueField="GenericNameHepDrug" SelectedValue='<%# Bind("GenericNameHepDrug") %>'
                            Width="300px" >
                                </asp:DropDownList>

CLearly I am lost. I have been working with ASP.NET VB for 2 months. I'm in over my head with figuring this one out - I've been at it for days. Can someone help. Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.