help finding an item in a datagrid

G

Guest

Using:
DataGrid1_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DataGrid1.ItemCommand

is there a way to find a specific item in the datagrid. I'm using the
CommandEvent to do some stuff. When I try to use syntax like this:

e.Item(1).FindControl("txtQuestion"), TextBox).Text

or other variations is says that e.item can not be used to find a particular
row, etc.

If there are say 5 rows in the datagrid and I want control("txtQuestion") on
row 2, how do I get that?

Once I click the commandevent I have the row, and fields, I'm on. But I also
need other rows values????

Make sense?

Thanx.
 
G

Guest

Hi Hope this helps,
I am using the following code to set some parameters in a dropdown box that
is a control in a data grid. This seems to work ok.
Dim dr_ctrl As DropDownList
dr_ctrl = CType(e.Item.Cells(8).FindControl("dr_lst_orig"), DropDownList)
dr_ctrl.Items.Insert(0, "Select ..")
dr_ctrl.SelectedIndex = 0
 
G

Guest

I'm not sure how this fits into my need.
You use cells(value) to locate the control, I can't. It's not available
apparently in CommandEventArgs.

"e.Item(1).FindControl("txtQuestion"), TextBox).Text

or other variations is says that e.item can not be used to find a particular
row, etc."

I'm on the code-behind.

Thanx.
 
J

Jeppe Dige Jespersen

If there are say 5 rows in the datagrid and I want control("txtQuestion") on
row 2, how do I get that?

Hmm.... i may be missing out on something, but how would this work for you?
Label1.Text = CType(DataGrid1.Items(2).FindControl("txtCompany"),
TextBox).Text

Now.... this requires that the txtCompany textbox is in a template column,
and ofcourse that the textbox is named "txtCompany".

Hope it helps.
Jeppe Jespersen
 
G

Guest

Thanx! don't know how I missed that.

Jeppe Dige Jespersen said:
Hmm.... i may be missing out on something, but how would this work for you?
Label1.Text = CType(DataGrid1.Items(2).FindControl("txtCompany"),
TextBox).Text

Now.... this requires that the txtCompany textbox is in a template column,
and ofcourse that the textbox is named "txtCompany".

Hope it helps.
Jeppe Jespersen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top