Solved

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

Posted on 2004-04-23
8
706 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
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 1

Assisted Solution

by:warmach
warmach earned 125 total points
Comment Utility
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
Comment Utility
Actually I want this on the server side?

Thanks,

Roger
0
 
LVL 1

Expert Comment

by:warmach
Comment Utility
ASP.NET does not have access to anything that happens client side.  What are you tryin to do?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 8

Author Comment

by:Rog
Comment Utility

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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

17 Experts available now in Live!

Get 1:1 Help Now