[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

populate label or txtbox from a datagrid

Posted on 2005-05-16
14
Medium Priority
?
261 Views
Last Modified: 2010-04-07

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
0
Comment
Question by:vbturbo
  • 7
  • 4
  • 3
14 Comments
 
LVL 33

Accepted Solution

by:
raterus earned 400 total points
ID: 14010854
it looks like you already have it done??  Are you just having a problem getting this event to fire?  Try using a ButtonColumn, with the CommandName set to "Select"

<columns>
  <asp:buttoncolumn commandname="Select" Text="Select this row" />
  ...
</columns>
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 400 total points
ID: 14011449
You can create a Select button column for selecting rows in the DataGrid.

Bob
0
 
LVL 18

Author Comment

by:vbturbo
ID: 14011772
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
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 33

Expert Comment

by:raterus
ID: 14011811
There is no concept of a SelectedItem in the datagrid without setting the DataGrid.SelectedIndex property.
0
 
LVL 18

Author Comment

by:vbturbo
ID: 14012012
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


0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 14012020
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
0
 
LVL 96

Expert Comment

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

(2) Not sure about that one.

Bob
0
 
LVL 18

Author Comment

by:vbturbo
ID: 14012152
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


0
 
LVL 33

Expert Comment

by:raterus
ID: 14012865
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)
0
 
LVL 18

Author Comment

by:vbturbo
ID: 14013149
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
0
 
LVL 18

Author Comment

by:vbturbo
ID: 14014309
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
0
 
LVL 33

Expert Comment

by:raterus
ID: 14014344
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?
0
 
LVL 18

Author Comment

by:vbturbo
ID: 14015026
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


0
 
LVL 18

Author Comment

by:vbturbo
ID: 14030244
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
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

829 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