Solved

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

Posted on 2004-04-23
8
708 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
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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

777 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