Click here to Skip to main content
15,898,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I need help with this.

I have a dropdownlist which contains names from 'Emp_Tab' table having
'Name' column.

I also have a gridview having datasource from 'Emp_Tab'.

Whenever I select any name from ddlist, I want the particular row with that name to get highlighted.

I am not able to figure it out.

Any suggestions?
Posted
Updated 3-Nov-10 22:32pm
v2
Comments
Ankur\m/ 4-Nov-10 7:25am    
Please do not add answer if it's not an answer. Use 'Add Comment' below user's answer to discuss with him. This notifies him of your comment.

1 solution

Hello ,
if you have the grid view .
XML
<asp:GridView ID="gvEmployees" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" DataSourceID="objGroups" OnRowCommand="gdvGroups_RowCommand" Width="60%" meta:resourcekey="gdvGroupsResource1">
    <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
    <RowStyle BackColor="#E3EAEB" />
    <Columns>
        <asp:BoundField HeaderText="Employee ID" />
        <asp:BoundField HeaderText="Employee Name" />
    </Columns>
    <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
    <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
    <EditRowStyle BackColor="#7C6F57" />
    <AlternatingRowStyle BackColor="White" />
</asp:GridView>


You write this code in ddl selected index changed function.
C#
protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
    gvEmployees.DataBind();//return rows colors to normal
    foreach (GridViewRow row in gvEmployees.Rows)
    {
        if (row.Cells[1].Text == ddl.SelectedItem.Text)
        {
            row.BackColor = System.Drawing.Color.Blue;
        }
    }
}


That's it!
Regards

Abraheem Abulubbad
.NET Developer
 
Share this answer
 
v2
Comments
m@dhu 4-Nov-10 5:40am    
Good call.
imaa2amha 4-Nov-10 6:59am    
thanx.
Ankur\m/ 4-Nov-10 7:25am    
[moved from answer]
OP wrote:
hey Abraheem.. thanks a load....
sometimes small concept goes off the head.. Smile

that was useful...
thanks che
imaa2amha 6-Nov-10 4:49am    
your welcome

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