Solved

How do I mouseover a cell in my DataGrid and retrieve a value from that row?

Posted on 2014-11-11
2
349 Views
Last Modified: 2015-01-20
Hello, I have a DataGrid and want to be able to mouseover a (LinkButton, HyperLink, <a></a>) control / tag (which ever is easiest of the 3, or possibly all), and somehow retrieve a value from one of the fields (databound fields) in that row. I then want to take that value and perform some processing with it behind the scenes in C#. How would I do this?

my DataGrid

<asp:DataGrid ID="dgSummary" runat="server" AllowPaging="True" AllowSorting="true"
                                PagerStyle-Mode="NumericPages" PagerStyle-Position="TopAndBottom" PagerStyle-HorizontalAlign="center"
                                PagerStyle-BackColor="#CCCCCC" PagerStyle-NextPageText="Next Page" PagerStyle-PrevPageText="Prev Page"
                                Font-Size="14px" AutoGenerateColumns="False" CellPadding="2" PageSize="10" Width="80%"
                                OnPageIndexChanged="dgSummary_PageIndexChanged" OnSortCommand="dgSummary_SortCommand"
                                OnItemCommand="dgSummary_ItemCommand">
                                <HeaderStyle BackColor="#CCCCCC" HorizontalAlign="Center" Font-Bold="true"></HeaderStyle>
                                <Columns>
                                    <asp:TemplateColumn Visible="false">
                                        <ItemTemplate>
                                            <asp:Label ID="lblPSEQ" runat="server" Text='<%# Eval("PSEQ") %>' />
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn Visible="false">
                                        <ItemTemplate>
                                            <asp:Label ID="lblCompName" runat="server" Text='<%# Eval("PNAME") %>' />
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <%--<asp:BoundColumn HeaderStyle-Width="425px" HeaderText="Name" DataField="PNAME" SortExpression="PNAME" />--%>
                                    <asp:TemplateColumn HeaderText="Company Name" ItemStyle-Width="100em" HeaderStyle-ForeColor="#034AF3"
                                        ItemStyle-HorizontalAlign="Center">
                                        <ItemTemplate>
                                            <asp:LinkButton ID="lnkbtnGoogleMap" Text='<%# Eval("PNAME") %>' CommandName="GoogleMap"
                                                runat="server" OnClientClick='_blank'/>
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:BoundColumn HeaderStyle-Width="400px" HeaderText="City" DataField="PCITY" SortExpression="PCITY"
                                        ItemStyle-HorizontalAlign="Center" />
                                    <asp:BoundColumn HeaderStyle-Width="75px" HeaderText="State" DataField="PSTATE" SortExpression="PSTATE"
                                        ItemStyle-HorizontalAlign="Center" />
                                    <asp:BoundColumn HeaderStyle-Width="400px" HeaderText="Summary Count" DataField="PCOUNT"
                                        SortExpression="PCOUNT" ItemStyle-HorizontalAlign="Center" />
                                    <asp:TemplateColumn HeaderText="Details" ItemStyle-Width="400px" HeaderStyle-ForeColor="#034AF3"
                                        ItemStyle-HorizontalAlign="Center">
                                        <ItemTemplate>
                                            <asp:LinkButton ID="lnkButton" Text="Show Details" CommandName="ShowDetails" runat="server" />
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                </Columns>
                            </asp:DataGrid>

Open in new window

0
Comment
Question by:mikesExpertExchange
2 Comments
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 40435555
The mouseover is client side . . . so you would have to do your processing in javascript or from javascript call a __doPostback / ajax call to do the processing in the code behind.

As for the value if you pass in the control you should be able to get it.

EG:

<!-- Bind the commandArgument to the value you're looking for for easy processing -->
 <asp:LinkButton ID="lnkButton" Text="Show Details" CommandName="ShowDetails" runat="server" CommandArgument='<%# Eval("MyCol") %>' onmouseover="MyJavaScriptFunction(this);"/>

<script>
MyJavaScriptFunction(ctrl)
{
var value = ctrl.getAttribute('commandArgument');
  // do something.
}
</script>
0
 
LVL 1

Author Closing Comment

by:mikesExpertExchange
ID: 40560148
Thank you.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now