Solved

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

Posted on 2014-11-11
2
345 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 39

Accepted Solution

by:
Kyle Abrahams earned 500 total points
Comment Utility
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
Comment Utility
Thank you.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

772 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

10 Experts available now in Live!

Get 1:1 Help Now