473,322 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Conditionally Showing DropDown List in DataGrid

HI ALL
Plz Help Me.
I have a datagrid with a few colums. One column is conaining 1's or 0's.
Its like a flag column. It either has 0 or 1. Now what i need is that if any row has 1 in this column than another column named "Status" (of that row) should have a dropdown list conatining 4 items.
This column can have values Checked,NotChecked,InProcess,Pending in the rows for which the flag column has 0's. But when the Flag value is 1 then this column should have a drop down list in that paricular cell (with Checked,NotChecked,InProcess,Pending as the items)
plz note That I DONT WANT ANY EDIT or SELECT BUTTON IN ANY ROW.
I mean the dropdown should appear automatically and not by pressing of any button..
ITS URGENT. PLZ HELP ANYBODY
Mar 4 '08 #1
2 1532
nateraaaa
663 Expert 512MB
HI ALL
Plz Help Me.
I have a datagrid with a few colums. One column is conaining 1's or 0's.
Its like a flag column. It either has 0 or 1. Now what i need is that if any row has 1 in this column than another column named "Status" (of that row) should have a dropdown list conatining 4 items.
This column can have values Checked,NotChecked,InProcess,Pending in the rows for which the flag column has 0's. But when the Flag value is 1 then this column should have a drop down list in that paricular cell (with Checked,NotChecked,InProcess,Pending as the items)
plz note That I DONT WANT ANY EDIT or SELECT BUTTON IN ANY ROW.
I mean the dropdown should appear automatically and not by pressing of any button..
ITS URGENT. PLZ HELP ANYBODY
You are going to need to loop through the rows of your datagrid and determine whether you need to show a label or a drop down list in the Status column. Here is how to do it.

Expand|Select|Wrap|Line Numbers
  1.  for(int i = 0; i < datagrid.Items.Count; i++) 
  2. {
  3. ddl = (DropDownList)datagrid.Items[i].FindControl("ddlStatus");
  4. ddl.DataSource = dataset;
  5. ddl.DataTextField = "status_description";
  6. ddl.DataValueField = "status_description_id";
  7. ddl.DataBind();
  8.  
  9. lbl = (Label)datagrid.Items[i].FindControl("lblStatus");
  10. lbl.Visible = true;
  11.  
  12. if(datagrid.Items[i].Cells[3].Text == "1") 
  13. //3 would be the column number of the Status column
  14. {
  15. lbl.Visible = false;
  16. }
  17. else
  18. {
  19. ddl.Visible = false;
  20. }
  21. }
  22.  
Hopefully this helps you. If you have another specific question after trying this code let me know.

Nathan
Mar 4 '08 #2
Thank you so much for replying...
I was able to do it in some what the same way....


<ItemTemplate >
<asp:Label ID="lblWithDrp" runat="server" Visible = <%#Convert.ToInt32(DataBinder.Eval(Container.DataI tem,"HiddenColumn"))==0%> Text ="LABEL"> </asp:Label>
<asp:DropDownList ID="drpInGv" runat="server" Visible = <%#Convert.ToInt32(DataBinder.Eval(Container.DataI tem,"HiddenColumn"))==1%>

</asp:DropDownList>
</ItemTemplate>
Mar 6 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Philip Townsend | last post by:
I have a datagrid that contains a dropdown list that is part of an EditItemTemplate. I need to run some code when the dropdown list builds in order to preselect an item in the list. Preselecting...
2
by: Michelle | last post by:
Hello, I put a dropdown list in ItemTemplate Column. I can select its value from the dropdown list and store in a dataset, but when I retrieve records from dataset, it doesn't show up in the...
3
by: Big Dave | last post by:
I know it's been asked a million times before, but I still can't seem to find an answer that works. I've got a dropdown list in the footer template of a datagrid. The dropdown list databinds,...
1
by: Vijay Kerji | last post by:
Hi, I have a datagrid with dropdown list and Remove hyperlink in it as columns. When I remove a row from the datagrid, Dropdown list selection is retaining its previous value. i.e, removed...
6
by: Jenna Alten | last post by:
I have a datagrid with a template column that contains a dropdown list. I currently fill and display the dropdown list on the page load. This is working correctly. I am NOT using an Edit Column. I...
2
by: Waran | last post by:
I Want to add a dropdown box in a datagrid on Page_Load. This Datagrid shares two tables. One table contains Employee details, and the other having the list of projects the employee is...
2
by: Peter | last post by:
ASP.NET 2003 In the DataGrid how do I select current cell value in the dropdown box when I click on the edit link, currently when I click on the edit link in the DataGrid the dropdown box...
6
by: yasodhai | last post by:
Hi, I used a dropdown control which is binded to a datagrid control. I passed the values to the dropdownlist from the database using a function as follows in the aspx itself. <asp:DropDownList...
4
by: youvrajasnsm | last post by:
Hi All, >I am using datagrid control in asp.net with C#. >I have two dropdown list in datagrid e.g. one dropdown have Classname and another have Studentname. >now I want to show all the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.