Link to home
Start Free TrialLog in
Avatar of vbturbo
vbturboFlag for Denmark

asked on

populate label or txtbox from a datagrid


hi all

I have datagrid poulated from a dataset
And now i need to populate these lbl's and txtbox's when a user click's on a row in the grid. would also be nice to highlight  the clicked row also

Hope some one got a tip


Private Sub DataGrid1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.SelectedIndexChanged
        Dim myText1,myText2,myText3 As String
        myText1 = DataGrid1.SelectedItem.Cells(0).Text
        myText2 = DataGrid1.SelectedItem.Cells(1).Text
        myText3 = DataGrid1.SelectedItem.Cells(2).Text
        Label1.Text = myText1
        Label2.Text = myText2
        Text1.Text = myText3
End Sub

any help is very much appreciated

rgds vbturbo
ASKER CERTIFIED SOLUTION
Avatar of raterus
raterus
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
SOLUTION
Avatar of Bob Learned
Bob Learned
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
Avatar of vbturbo

ASKER

Hi there

Thanks for reply..please carry over with me im not that sharp in asp.net

Usually i would in a win app just use the HitTestInfo to trigger the grids click event without haveing to use a Select button column

So just out of cosmetic reason can this be done without the button column ???..but for-example use the DataGrid1.SelectedItem.Cells(1).Text instead

rgds vbturbo
There is no concept of a SelectedItem in the datagrid without setting the DataGrid.SelectedIndex property.
Avatar of vbturbo

ASKER

Hi raterus and TheLearnedOne

thanks for all help... just one more issue

1) is it then possible to control the <asp:buttoncolumn commandname="Select" Text="Select this row" /> to be set to the left side of the grid ,at the
    momment it possioned ist the right side

2) what i meant was with the <asp:buttoncolumn commandname="Select" Text="Select this row" />  Was that in the  DataGrid1 collum no.1 i got a autonumber collum so, can i relate the <asp:buttoncolumn commandname="Select" Text="Select this row" /> to the  autonumber collum

                               (" commandname="Select" Text="1" ")
                               (" commandname="Select" Text="2" ")
                               (" commandname="Select" Text="3" ")

Hope dosn't sounds to weird

rgds vbturbo


ASP.NET doesn't have the richness that WinForms applications have when working with the DataGrid.  You might be able to accomplish this row selection with some JavaScript, but I don't have that kind of code.

Bob
(1) Make the select button the first column by rearranging the order in the HTML view.

(2) Not sure about that one.

Bob
Avatar of vbturbo

ASKER

Hi again

TheLearnedOne if you got hint or link/tip where i might could look up a javascript in this regard please post it.... even if it is a grab in the air

Any way thanks a lot


vbturbo, look into the DataKeys/DataKeyField property of the DataGrid, when you bind the datagrid, it can keep track of your primary key information for you, which you can relate to the current row.

primary_key = myDataGrid.DataKeys(myDataGrid.SelectedIndex)
Avatar of vbturbo

ASKER

hi raterus

Thank you ..ill give it a try
I will give you a feedback a little later on regardless if i succeed or not....any way thanks for takeing your time ....im gaining a lot from your and this site's expertise
i figure it will take me some time to ajust from ordinary winapp's features to ASP.NET stuff

many rgds vbturbo
Avatar of vbturbo

ASKER

hi raterus

Been reading on msdn about    DataKeys/DataKeyField property ...but soon as you need to delete,update or insert i can't see its possible to avoid
the buttoncolumn in the grid !
It might be possible to populate lables and txtboxes without buttoncolumn in the grid since you can map the primarykey to a collum from a datatable....hmm


But thanks for the tip ..it was very beneficery

Jens
buttoncolumns, or a button/linkbutton/imagebutton in a templatecolumn are pretty necessary when you start modifying the datagrid on a row by row basis.  There isn't much you can do around this, without using a hyperlink that links back to the same page (which I wouldn't suggest).  Any reason you are trying to avoid the buttoncolumns?
Avatar of vbturbo

ASKER

Hi

im building a ,,,cash register on a intranet in a hotel / resuarant  enviroment where a lot of the employe's are up age and not very computer experienced
it is more out of user friendlyness and in consideration of what they where used to.
earlier i build the app in a win.app but since the place are implmenting online booking and stock acounts the dission was to make the hole lot on intranet
since we are 3 different " free volunters " programmers  (1 php man , 1 oracle man ,and me in vb.net) and the hole is managed on 5 diff computers..(LAN)

so this is the answer to your question.

NB : and now im learning a hole new world of ASP.NET and html...and its tuff stuff for a newbee ...hi hi and you'll proberly see a question or 2 from me again

Regards Jens


Avatar of vbturbo

ASKER

Hi  raterus

Just to your info ..regarding your suggestion ("DataKeys/DataKeyField property of the DataGrid")

It was not possible to populate lables and txtboxes without buttoncolumn but soon as you map the primarykey i could at least hide the
auto-no. collum and represent the <asp:ButtonColumn> in numeric order

<Columns>
<asp:ButtonColumn  CommandName="Select" DataTextField ="IntegerValue" ButtonType=PushButton></asp:ButtonColumn>
</Columns>

token from the sample on msdn

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuiwebcontrolsbasedatalistclassdatakeystopic.asp

Jens