Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-04-23
8
Medium Priority
?
714 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 D
[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 375 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 D
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
Industry Leaders: 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!

 
LVL 8

Author Comment

by:Rog D
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 375 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

715 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