Solved

Dropdownlist in Datagrid with onselectchange event

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

821 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