Solved

Dropdownlist in Datagrid with onselectchange event

Posted on 2004-09-22
5
325 Views
Last Modified: 2008-02-01
Hi,
 I know this kind of question has been asked before but I couldnt find a concrete answer that closeley matched my problem.
Right now I have a Datagrid that looks like this
Name   Address    Phone    Edit   Delete   Generate No.
adf       adsfasd     12334   Edit   Delete    Generate No.

The last three columns are links to the repective pages with the CustomerID being passed through the links

I want to replace teh last 3 colums with 1 column that has a dropdownlist with Edit, Delete, Generate No. but keep the same functionality
The purpose is to save real estate on the page.

If someone has done something like this before and is willing to share the code, please help.

Thanks.
0
Comment
Question by:BrijBhasin
  • 2
  • 2
5 Comments
 
LVL 15

Accepted Solution

by:
praneetha earned 250 total points
ID: 12128770
have a dropdownlist in a itemtemplate and bind it in itemdatabound

do this in itemdatabound

private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
            {
                  if(e.Item.ItemType != ListItemType.Header && e.Item.ItemType != ListItemType.Footer)
                  {
                        System.Web.UI.WebControls.DropDownList ddl=(DropDownList)e.Item.FindControl("DropDownList1");
                        ListItem li=new ListItem("Add",e.Item.Cells[1].Text); //say e.item.cells[1].text - contains the id which u want to pass in the link
                        ListItem li1=new ListItem("Delete",e.Item.Cells[1].Text);
                        ddl.Items.Add(li);
                        ddl.Items.Add(li1);
                  }
            }

now set the autopostback=true and when index changed redirect to other page with selected value as parameter (values contain id)

or write a javascript onchange and access the value and then response.redirect

good luck

0
 

Author Comment

by:BrijBhasin
ID: 12144346
praneetha,
  would you know how I can do this in VB and not C#?
0
 
LVL 15

Expert Comment

by:praneetha
ID: 12144430
well it should be same...u have itemdatabound in vb.net too....

and may be if loop looks diff and all that...otherwise it should be all same...

sorry i don't know much vb.net...but i am prety sure..it almost looks the same...

you just have to change the syntax..i am sure...events of datagrid are all same
0
 

Author Comment

by:BrijBhasin
ID: 12332777
Sorry praneetha I missed assigning the points to this question earlier.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

912 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now