Search This Blog

Tuesday, October 16, 2012

Gridview DropDownList Selected Index Changed Event & Get GridView Row Index

Still many of them searching forum for the Gridview and DropDownList inside it in any template. And they want to trigger the event, and want to get the row index of the gridview and other control's value in the same row. So I have posted this for GridView DropDownList...

Gridview Markup

<asp:TemplateField HeaderText="Address">
<asp:TextBox ID="txtEAddress" Width="100px" runat="server" Text='<%# Bind("Address") %>'></asp:TextBox>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Address") %>'></asp:Label>
<asp:TextBox ID="txtAddress" runat="server" Width="100px" TextMode="MultiLine"></asp:TextBox>

Code Behind

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        DropDownList ddl = (DropDownList)sender;
        GridViewRow row = (GridViewRow)ddl.Parent.Parent;
        int idx = row.RowIndex;

        TextBox txtECustCode = (TextBox)row.Cells[0].FindControl("txtECustCode");
        string _text1 = txtECustCode.Text.ToString();


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.