Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi

selected row in gridview values display in two labels(i.e. name in one label and salary in one label). i dont know how?
what should i use if i select multiple rows what should i use to display it.


XML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="3"
            GridLines="None" BackColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px"
            CellSpacing="1" >
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>

                        <input type="checkbox"  id="chk"/>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Name">
                <ItemTemplate>
                <%#Eval("EmpName") %>
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Emp Salary">
                    <ItemTemplate>
                        <%#Eval("salary") %>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
            <RowStyle BackColor="#DEDFDE" ForeColor="Black" />
            <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
            <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
        </asp:GridView>
Posted
Updated 13-Dec-11 1:18am
v2
Comments
_Tushar Patil 13-Dec-11 7:38am    
You want to show Selected record in Gridview in Label...?
yerrojumeher 13-Dec-11 7:39am    
ya
yerrojumeher 13-Dec-11 7:40am    
can u help me i am stuck there
Anuj Banka 13-Dec-11 8:06am    
You want all these things in code behind or on client side

You need to add a commandfield for select. Then from that try these codes in your GridView1 SelectedIndexChanged event:

C#
lblName.Text = GridView1.SelectedRow.Cells[1].Text;
lblSalary.Text = GridView1.SelectedRow.Cells[2].Text;


And that should do it from here.

Regards,
Eduard
 
Share this answer
 
 
Share this answer
 
Check this thread It will help you


Thread[^]
 
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