Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to select next row of grid view on selected index change event on dropdownlist in gridview...please help me
Posted

C#
protected void Select_Spin2_IndexChanged(object sender, EventArgs e)
        {
            DropDownList ddlSpin2 = (DropDownList)sender;
            GridViewRow gridrow = (GridViewRow)ddlSpin2.NamingContainer;
            int rowIndex = gridrow.RowIndex;
            foreach (GridViewRow row in GridView_Courses.Rows)
            {
                if (row.RowIndex == rowIndex+1)
                {
                   //now you are in next row. You can acces controls and make changes in the next line here
}
}
}


my aspx:
XML
<asp:TemplateField HeaderStyle-HorizontalAlign="Left" HeaderText="Spin2" ItemStyle-Width="10%"
                                                        HeaderStyle-ForeColor="White" HeaderStyle-BackColor="steelblue" HeaderStyle-BorderWidth="0"
                                                        HeaderStyle-BorderStyle="Dashed" HeaderStyle-BorderColor="Black">
                                                        <ItemTemplate>
                                                            <asp:DropDownList runat="server" ID="Select_Spin2" AutoPostBack="true" OnSelectedIndexChanged="Select_Spin2_IndexChanged" />
                                                        </ItemTemplate>
                                                        <HeaderStyle HorizontalAlign="Left" />
                                                        <ItemStyle Width="10%" />
                                                    </asp:TemplateField>
 
Share this answer
 
v2
Comments
[no name] 30-Aug-12 3:31am    
which is this event???where it is in the grid view control?
Santhosh Kumar Jayaraman 30-Aug-12 3:33am    
i have posted my dropdowncolumn code inside gridview from aspx page.
[no name] 30-Aug-12 3:48am    
ok and how we can show just one row in the grid view and after that code one by one all rows shown to us?
Santhosh Kumar Jayaraman 30-Aug-12 4:14am    
sorry i ddint get your question
[no name] 30-Aug-12 4:20am    
read my next question that i posted right now
Find the cureent ItemIndex in your selected index change event of dropdownlist and try the following codes:
C#
//gvTest.Rows[index + 1].RowState = DataControlRowState.Selected;
gvTest.SelectedIndex = index + 1;
//index is your current row index of gridview where dropdownlist is selected



--Amit
 
Share this answer
 
v2
Comments
[no name] 30-Aug-12 3:28am    
where it can be written?
_Amy 30-Aug-12 3:30am    
In the selected index changed event of dropdownlist.
[no name] 30-Aug-12 3:31am    
but how to fire the event of drop down list in the grid view control
_Amy 30-Aug-12 3:35am    
Try:
<asp:DropDownList ID="logList" runat="server" AutoPostBack="True"
onselectedindexchanged="itemSelected">
Place this inside gridview.
And
protected void itemSelected(object sender, EventArgs e)
{
//Your code goes here
}
[no name] 30-Aug-12 3:51am    
what is that
gvTest.SelectedIndex = index + 1;
index????

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