Solved

ASP.Net Datagrid, get Cell contents when mouse down?

Posted on 2004-04-23
8
711 Views
Last Modified: 2010-10-05
I would like to get the cell contents of an asp.net datagrid when the mouse is down?  Is there a way to get this?


Thanks,

Rog
0
Comment
Question by:Rog
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 1

Assisted Solution

by:warmach
warmach earned 125 total points
ID: 10902268
You are asking for something that occurs on the client side.  So you would need to write javascript to get that information.

Try this...

Dim Cell1 as TableCell = New TableCell()

Cell1.Attributes.Add("onmousedown", "GetInfo(this);")

The only way you will be able to get the information back to the server will have to dump the data into a hidden field and then post back to the server.

0
 
LVL 8

Author Comment

by:Rog
ID: 10902318
Actually I want this on the server side?

Thanks,

Roger
0
 
LVL 1

Expert Comment

by:warmach
ID: 10902451
ASP.NET does not have access to anything that happens client side.  What are you tryin to do?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 8

Author Comment

by:Rog
ID: 10902474

I am filling up the datagrid with some data.  I wan the user to be able to click on a cell and then run some code.

This grid is a transposed reocrdset so getting the cell information is cruicial.  This then will run some server code and either repost the page or go to another page.

Rog
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 10902989
You can not set onclick event to a cell of a datagrid or to a tablecell :(
the only  way of doing what you want is to use javascript as warmach
create a hidden field like this <input type="hidden" id="hSelectedCell" runat="server">
in your javascript function set the value of hSelectedCell to the selected cell's id and submit page
in the code behind check what is the value of this field - get the datagrid.items(indexrow).cells(indexcell) info and do whatever you want

B..M
0
 
LVL 4

Accepted Solution

by:
Kittrick earned 125 total points
ID: 10904865
The mouse has to do with client-side scripting, and ASP.NET is server-side. You can mix the two, but you may have to do it in two steps with a script based on what the server does.  As for showing the cell contents, you can print them by putting the converted column in the Response.Write() .

As for the cell contents of your datagrid, here is an example using a MS ACCESS Database:

<------------START CODE-------------->

'This subfunction will post the data selected on the page, by calling the array space in the database
Sub ViewDetails(sender as Object, e As DataGridCommandEventArgs)

'associating the colums with the values within by cell references based on order of fields on the page
    Dim buttonColumn as TableCell = e.Item.Cells(0)
    Dim IdColumn as TableCell = e.Item.Cells(1)

'declaring conversion variables and converting the cells into strings, numbers dates etc.    
    Dim buttonColText as String = buttonColumn.Text
    Dim IdColText as String = IdColumn.Text

'declaring an interim variable to post back to the page as a reference based on id of label

    Id.Text = IdColText

end sub

'----start datagrid---->

 <asp:DataGrid runat="server" id="Infant_Log"
         Font-Size="7pt" AutoGenerateColumns="false"
                      OnItemCommand="ViewDetails">
        <HeaderStyle BackColor="Black" ForeColor="White" Font-Bold="True" HorizontalAlign="Center" />
        <AlternatingItemStyle BackColor="lightGray" />


             
        <Columns>
              <asp:ButtonColumn Text="Details" HeaderText="Details" ButtonType="PushButton" commandname="Details"/>
            <asp:BoundColumn DataField="Id" HeaderText="BDID" visible="true"/>
                        </Columns>
      </asp:datagrid>


</script>

0
 
LVL 4

Expert Comment

by:Kittrick
ID: 10944847
sorry about this, but I screwed up the code. it should look like this:


The mouse has to do with client-side scripting, and ASP.NET is server-side. You can mix the two, but you may have to do it in two steps with a script based on what the server does.  As for showing the cell contents, you can print them by putting the converted column in the Response.Write() .

As for the cell contents of your datagrid, here is an example using a MS ACCESS Database:

<------------START CODE-------------->

'This subfunction will post the data selected on the page, by calling the array space in the database
Sub ViewDetails(sender as Object, e As DataGridCommandEventArgs)

'associating the colums with the values within by cell references based on order of fields on the page
    Dim buttonColumn as TableCell = e.Item.Cells(0)
    Dim Id_Column as TableCell = e.Item.Cells(1)

'declaring conversion variables and converting the cells into strings, numbers dates etc.    
    Dim buttonColText as String = buttonColumn.Text
    Dim Id_ColText as String = Id_Column.Text

'declaring an interim variable to post back to the page as a reference based on id of label

    Id_.Text = Id_ColText

end sub

'----start datagrid---->

 <asp:DataGrid runat="server" id="Infant_Log"
        Font-Size="7pt" AutoGenerateColumns="false"
                     OnItemCommand="ViewDetails">
       <HeaderStyle BackColor="Black" ForeColor="White" Font-Bold="True" HorizontalAlign="Center" />
       <AlternatingItemStyle BackColor="lightGray" />

<asp:textbox id="Id_" runat="server"/>
           
       <Columns>
             <asp:ButtonColumn Text="Details" HeaderText="Details" ButtonType="PushButton" commandname="Details"/>
          <asp:BoundColumn DataField="Id" HeaderText="BDID" visible="true"/>
                       </Columns>
     </asp:datagrid>


</script>

<!-------------end code------>

Where I screwed up was with the calling of the text from the codebehind because I had two controls (the textbox and the datagridcolumn) with the same id of ID. They have to be different or they will generate errors/exceptions, so I just gave the textbox an underscore. This code was taken from a living breathing project I'm working on, and it works.  
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

623 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