Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Deal All

I have gridview with multiple record.

gridview has two column.

First column has dropdown & second column has button.

I want show detail of selected item onclick of button of that particular row.

I can able to show the detail of first row dropdown item but not the other row dropdown item.

Basically problem is in row index of selected row.


Any suggestion.

Thanking you in advance.
Posted

 
Share this answer
 
Comments
Mahesh Devikar 9-Sep-13 5:32am    
Thank You Rohan...

But it wont fulfill my requirement.

I have done the same exercise without dropdown control.

But for each row of grid view each drop down has different items.

what i want is selected item value as row index of that particular row.
Thanks7872 9-Sep-13 5:34am    
I provided link to let you know how it works. No one here will provide you complete code for that. It will fulfill your requirement only if you put some effort your self. You can find tons of links on this with simple google search.
Hi,

try this.

// your gridview command event
C#
protected void yourgrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
    GridViewRow row = (GridViewRow)(((Button)e.CommandSource).NamingContainer);
    DropDownList ddl = (DropDownList)row.FindControl('yourdropdownid');
    // now select value
    string value = ddl.SelectedValue;
}


hope it helps.
 
Share this answer
 
>Guys Finally got Solution...........

Thanks to Harshit Rawal also.

Explanation:

The RowIndex of the GridView Row is contained in the CommandArgument Property. Thus with that index you can get the reference of the GridView Row.

My Griedview is like this ..

XML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowCommand="OnRowCommand">                                                                               <Columns>                                                                                    <asp:ButtonField CommandName="View" ButtonType="Button" />                                                                                    <asp:TemplateField>                                                                                        <ItemTemplate>                                                                                            <asp:DropDownList ID="ddlitem" runat="server">                                                                                            </asp:DropDownList>                                                                                        </ItemTemplate>                                                                                    </asp:TemplateField>                                                                         </Columns>
</asp:GridView>

What i want i got it on handling OnRowCommand of my gridview


VB
Protected Sub OnRowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)

If e.CommandName = "View" Then
            Dim i As Integer = Convert.ToInt32(e.CommandArgument)
            Dim ddl As DropDownList = DirectCast(GridView1.Rows(i).FindControl("ddlitem"), DropDownList)
            Dim x As String = ddl.SelectedValue

        End If


End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900