Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-04-23
8
Medium Priority
?
715 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
  • 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
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 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month10 days, 11 hours left to enroll

885 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