Link to home
Start Free TrialLog in
Avatar of mbizup
mbizupFlag for Kazakhstan

asked on

Full Row Selection in a Datagrid

Hi,

I'd like to set up full row selection on a datagrid, so that the user can make a selection by clicking anywhere in a given row, so that I can hide or eliminate the "select" column.  Any Ideas on how to do this?

(VB.Net 2003)

Thanks for all your help.
Avatar of arch_great
arch_great

DataGrid1.Select(DataGrid1.CurrentRowIndex) (in the keyup event of the grid)

-Archana
HI mbizup,
             The solution to ur problem is that u have to call the method which datagrid calls when select button is clicked.

What u have to do is that

Add one select button to datagrid and that u can hide as per ur requirment.

now Add following code to ur Datagridname_ItemCreated method

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.SelectedItem)
                  {
                                                e.Item.Attributes.Add("onmouseover", "this.style.cursor='hand'");
                                                string jScript = "javascript:__doPostBack('" + this.UniqueID.ToString() +"$dgSearchResult$" + "_ctl" + (e.Item.ItemIndex + 3) + "$LinkButton1','')";
                        e.Item.Attributes.Add("onclick", jScript);
                  }

where dgSearchResult is name of my datagrid


Regards,
SandeepRR
Avatar of mbizup

ASKER

Thanks for your replies.  

arch_great:
The Keyup event did not show up in the VB editor's intellisense -- VB.Net 2003

SandeepRR:
My C skills are a little rusty.  Do you know how to translate that to BASIC? This is what I have so far:

Dim jScript as string
if e.Item.ItemType =ListItemType.Item OR e.Item.ItemType = ListItemType.AlternatingItem OR  e.Item.ItemType = ListItemType.SelectedItem Then
      e.Item.Attributes.Add("onmouseover", "this.style.cursor='hand'")

      '**** This is where I'm having trouble, and my interpretation...
      ' C
      'string jScript = "javascript:__doPostBack('" + this.UniqueID.ToString() +"$dgSearchResult$" + "_ctl" + (e.Item.ItemIndex + 3) + "$LinkButton1','')";
       'BASIC
       jScript = "javascript:__doPostBack('" & this.UniqueID.ToString() & "dgSurveyResponses" & "_ctl" & (e.Item.ItemIndex + 3) & "LinkButton1,'')")

      e.Item.Attributes.Add("onclick", jScript);
End IF

I have a couple of questions about the jScript string:
It doesn't compile because "This." is not recognized.  Should This.UniqueID be inside the jscript string?  
What is LinkButton1?  Is that the name of your Select button column?
Is e.Item.ItemIndex + 3  the location of the Select column?

Is the resultant string supposed to look somehing like this (my datagrid is dgSurveyResponses)?
    javascript:__doPostBack('dgSurveyResponses_ctl3LinkButton1,'')

If not, what would a harrdcoded version of this string look like?  (That might help me figure out the VB)

thanks!

           
Avatar of mbizup

ASKER

Hi,

I was unable to get this working.  I worked out the syntax, but it didn't look like the SelectedIndexChanged event was firing.  The screen would flash in response to clicking on columns other than the Select column, but the code behind the SelectedIndexChanged event did not execute.  

I found a sloppy workaround that did the trick for this particular page.  I changed all the columns to Select columns, using the DataTextField property to associate the columns with the appropriate fields in the underlying query.

I will ask CS to close this question.

Thanks fpr your help.
SOLUTION
Avatar of SandeepRR
SandeepRR
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mbizup

ASKER

Hi,

Thank you both for the responses.  I really would like to get this working by the methods you have posted rather than my work around.  The code makes sense to me... basically associating the click of the other columns with the select column.  

SandeepRR,

The Me.UniqueID caused an Invalid Object error (or something like that).  When I took that part of the statement out, It compiled okay.  When I clicked on a non-select column, the screen flickered (so I feel that this is very close) but the SelectedIndexChanged code did not run.

Can you explain what the e.Item.ItemIndex + 3 part of the code does?


Rejojohny,

I'm pretty new to HTML... I placed the code from the URL you posted at the end of the HTML, and it just showed up as text on my page in the browser.  Roughly where in the HTML code should I place it?  I know thats a very vague question since you can't see my application, but If you give me a ballpark idea I can work with it...

Some more info about my datagrid (I don't know if this plays a role here)... The grid is bound to fields in an SQL Server table.

Thank you both for all the help.  
Avatar of mbizup

ASKER

Okay, both of these solutions work beautifully.  Turns out I was missing the <Script>  things in my HTML and that was why the HTML code was showing up as text in the browser (I am a noob).  Thank you both again for your help.
Avatar of mbizup

ASKER

Sandeep, That code converter is a great reference!