-1

I am using asp.net web forms and have following concern.

I have one aspx page having asp:DropDownList and Gridview with asp:HyperLinkField in each column. So I want to set the value of selected DropDownList to hyperLinkField tag dynamically either code behind or inside the following code.

<asp:HyperLinkField Text="Merge" DataNavigateUrlFields="MemberId" Target="_blank" DataNavigateUrlFormatString='/MergeMember.aspx?memberid={0}&clubid={1}" />

As you can see I have bind the field called MemberId in {0} and now I want to set the selected value of dropdownlist in {1}. Setting {1} is just a demo to show where I really want to set the value of selected dropdownlist I have't implemented that yet.

If it is possible please guide how?

If it is not possible please guide me how I can achieve this using different approach? Thanks in advance.

Mahavirsinh Padhiyar
  • 1,299
  • 11
  • 33

1 Answers1

2

.aspx Page

<asp:DropDownList ID="ddlTest" runat="server">
</asp:DropDownList>

        <asp:GridView ID="grdTesting" runat="server" AutoGenerateColumns="false" Width="98%">
            <Columns>
                <asp:TemplateField HeaderText="Job Number">
                    <ItemTemplate>
                        <asp:LinkButton ID="lnkTest" runat="server" Text='<% # Bind("Test") %>' ToolTip='<%# Bind("Test") %>'
                            OnClick="lnkTest_Click"></asp:LinkButton>
                        <asp:HiddenField ID="hdnId" runat="server" Value='<% # Bind("Id") %>' />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

.aspx.cs

   protected void lnkTest_Click(object sender, EventArgs e)
    {
        GridViewRow gvr = (GridViewRow)((Control)sender).Parent.Parent;
        HiddenField hdnId = (HiddenField)gvr.FindControl("hdnId");
        Response.Redirect("frmTest.aspx?Id=" + Convert.ToString(hdnId.Value) + "&DropDownId=" + ddlTest.SelectedValue, false);
    }

Note:-

I think you have to change your Logic.....

In above Example...I'm binding a Gridview with Linkbutton and Id

On click of link button you can redirect to other page(as per your Logic..) with sending Query string value(Id and Dropdownlist value)

I'm using asp.net with c# 4.5

Get external dropdownlist value here

Mahavirsinh Padhiyar
  • 1,299
  • 11
  • 33
THE LIFE-TIME LEARNER
  • 1,476
  • 1
  • 8
  • 18