Link to home
Start Free TrialLog in
Avatar of LoveToSpod
LoveToSpodFlag for United Kingdom of Great Britain and Northern Ireland

asked on

SelectedIndexChanged event on datagrid

Hi,

I 'm trying to get my datagrid SelectedIndexChanged do the following:

User clicks the 'Select' command on the datagrid. The value of a field in the datagrid's selected record is passed to a public variable ('strSelectedDepotID'), then a different web-page opens and loads the specific record using the public variable as the criteria.

1. I need the SelectedIndexChanged event code to get the value of field whose HeaderText: is 'ID', and DataField: 'DepotID' of the selected record in datagrid1. I have tried using following without any luck:

DOESN'T WORK:
SqlCommand1.Parameters("@DepotID").Value = e.Item.Cells(2).Text
strSelectedDepotID = e.Item.Cells(2).Text
strSelectedDepotID = CType(DataGrid1.SelectedItem.FindControl("ID"), Label).Text

2. What is the event code to open a different web-page? (Page called 'EditFSLInfo.aspx'). When this page loads, I can then use the public variable passed in step1 to load the specific record - (I can do this bit )

ASKER CERTIFIED SOLUTION
Avatar of orbulat
orbulat
Flag of Hong Kong 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
this should also work

ddl .Attributes.Add("onChange","goToPage(this);");

function goToPage(ddl)
{
   var newLink = "EditFSLInfo.aspx?id="+ddl.options[ddl.selectedIndex].value;
   location.href = newLink;
}
Avatar of LoveToSpod

ASKER

Hey Orbulat:

Your code above helped me discover that I've got all tangled up.

I should be using the ItemCommand event, not the SelectedIndexChanged. DOH!!!!!!!!!!  Using this with code: (strSelectedDepotID = e.Item.Cells(2).Text) has passed the DepotID to the Vaiable! Cool, Step1 fixed. 250pts for you so far!

Step 2: How do I now redirect to Page called 'EditFSLInfo.aspx'.

I can see you have provided a C# suggestuion above, but the event is wrong (sorry...). Can C# be embedded into vb.net? Do I just paste it in? If so give me the C# code, else I'll need the VB.NET code.

Cheers,

LTS
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
orbulat

The overall solution is:

1. strSelectedDepotID = e.Item.Cells(2).Text
2. Response.Redirect("SERVERNAME/technicalCourier/SecretFiles/EditFSLData.aspx")

Simple as that. I did deduce the answer assisted by your suggestions. (Remember the problem was I was using the wrong event. I should have been using ItemCommand event, not the SelectedIndexChanged as I wasn't even using a ddl). Will be useful for the future I'm sure ;)

Thanks, LTS
ar, I misunderstood "event code for opening webpage" :-p

anyway, it's great that everything works now :o)