Solved

Dropdownlist in Datagrid with onselectchange event

Posted on 2004-09-22
5
317 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

10 Experts available now in Live!

Get 1:1 Help Now