Solved

Dropdownlist in Datagrid with onselectchange event

Posted on 2004-09-22
5
359 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

623 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