• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

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
0
vbturbo
Asked:
vbturbo
  • 7
  • 4
  • 3
2 Solutions
 
raterusCommented:
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
 
Bob LearnedCommented:
You can create a Select button column for selecting rows in the DataGrid.

Bob
0
 
vbturboAuthor Commented:
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
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.

 
raterusCommented:
There is no concept of a SelectedItem in the datagrid without setting the DataGrid.SelectedIndex property.
0
 
vbturboAuthor Commented:
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
 
Bob LearnedCommented:
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
 
Bob LearnedCommented:
(1) Make the select button the first column by rearranging the order in the HTML view.

(2) Not sure about that one.

Bob
0
 
vbturboAuthor Commented:
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
 
raterusCommented:
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
 
vbturboAuthor Commented:
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
 
vbturboAuthor Commented:
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
 
raterusCommented:
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
 
vbturboAuthor Commented:
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
 
vbturboAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 7
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now