Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 663
  • Last Modified:

What is GridView Row Value After GridView DropDown Control SelectedIndexChanged Event

Greetings;

I have a GridView control with a DropDown control in cell 0.

I need to know what is the row in the GridView control after the DropDown control's SelectedIndexChanged event is fired using Visual Basic 2008.

Much thanks ... David
0
David Bach
Asked:
David Bach
  • 3
  • 3
1 Solution
 
Bob LearnedCommented:
You should be able to get the GridViewRow from the DropDownList's control hierarchy available through the Parent property.

Example coded in the comment block:

    Dim row As GridViewRow = TryCast(ddl1.Parent.Parent, GridViewRow)

I believe that the hierarchy is DropDownList, cell, row.
0
 
David BachAuthor Commented:
Greetings TheLearnedOne;

I don't see from your example how I get around needing to know the row of the dropdown control prior to the TryCast function. The dropdown control is a column within the GridView control.

Can you help me understand this better?


Much thanks ... David
0
 
Bob LearnedCommented:
David,

What are you really asking?  It sounded like you were trying to get the row from the DropDownList control, so that you could perform some other operation on the row.  If that is not the case, please explain your question differently.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
David BachAuthor Commented:
Greetings TheLearnedOne;

I apologize for not being more detailed. I hope the following will explain what I'm attempting to do more clearly.

Attached is the HTML for the GridView control;

I need to know what the grid row is when a user changes the selection of the DropDown control with the Id of "ddlPatient".

Much thanks ... David
<asp:GridView ID="gvPrescription" runat="server" AutoGenerateColumns="False" CellPadding="0"
      CellSpacing="4" GridLines="None" Width="100%">
      <Columns>
        <asp:TemplateField HeaderText="Patient">
          <ItemTemplate>
            <asp:DropDownList ID="ddlPatient" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlPatientDependent_SelectedIndexChanged"
              CommandName="PatientChange">
            </asp:DropDownList>
          </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Delete">
          <ItemTemplate>
            <asp:CheckBox ID="cbxDelete" runat="server" AutoPostBack="True" CommandName="Delete"
              OnCheckedChanged="cbxDelete_CheckedChanged" />
          </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
          <ItemTemplate>
            <asp:RadioButtonList ID="rblPickupDeliver" runat="server" SelectedValue='<%# Bind("strDeliver") %>'>
              <asp:ListItem Value="D">Deliver</asp:ListItem>
              <asp:ListItem Value="P">Pickup</asp:ListItem>
            </asp:RadioButtonList>
          </ItemTemplate>
          <ItemStyle Wrap="False" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Contact<br />Doctor?">
          <ItemTemplate>
            <asp:CheckBox ID="cbxCallDoctor" runat="server" Checked='<%# Bind("blnDoctorCall") %>' />
          </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Prescription No.">
          <ItemTemplate>
            <asp:TextBox ID="tbxPrescriptionNumber" runat="server" Text='<%# Bind("strPrescriptionNumber") %>'></asp:TextBox>
          </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Medication">
          <ItemTemplate>
            <asp:TextBox ID="tbxMedicationName" runat="server" Text='<%# Bind("strMedicationName") %>'></asp:TextBox>
          </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Status">
          <ItemTemplate>
            <asp:Label ID="lblStatus" runat="server"></asp:Label>
          </ItemTemplate>
          <ItemStyle Wrap="False" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Row Id" ShowHeader="False" Visible="False">
          <ItemTemplate>
            <asp:Label ID="lblRowId" runat="server" Text='<%# Bind("bigRowId") %>'></asp:Label>
          </ItemTemplate>
        </asp:TemplateField>
      </Columns>
      <EmptyDataTemplate>
        No prescriptions available.</EmptyDataTemplate>
      <SelectedRowStyle BackColor="#66FFFF" />
    </asp:GridView>

Open in new window

0
 
Bob LearnedCommented:
I showed you how to get the GridViewRow from the DropDownList control, and then you asked a confusing question that threw me off.

In the event handler for the ddlPatientDependent_SelectedIndexChanged event, you can get the GridViewRow from the DropDownList.


Protected Sub ddlPatientDependent_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        Dim ddlPatient As DropDownList = TryCast(sender, DropDownList)
        Dim row As GridViewRow = TryCast(ddlPatient.Parent.Parent, GridViewRow)
    End Sub

Open in new window

0
 
David BachAuthor Commented:
Dear TheLearnedOne;

I apologize again for the confusion in my initial post.

Much thanks for your time and assistance in helping me.


David
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now