473,323 Members | 1,547 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,323 software developers and data experts.

No Value: DropDownlist in EditItemTemplate Gridview Problem

Hi everybody,

I created a Gridview with a TemplateField and there is Label control in
ItemTemplate and a DropdownList control in EditItemTemplate, I was to
displayed them ok when I click the Edit Command button. But when I about to
get the value of this template field I get an empty string value. I check the
following the local dtFiles has data and the cells are visible at stage right
before foreach GridViewRow gr in gdvFiles.Rows) loop. Can anyone tell what is
missing or I went wrong? Thanks

Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="gdvFiles" runat="server"
  2. AutoGenerateColumns="False" ShowHeader="False" Width="649px"
  3. OnRowEditing="gdvFiles_RowEditing" OnRowUpdating="gdvFiles_RowUpdating">
  4. .....
  5. <asp:TemplateField HeaderText="FileType"
  6. ShowHeader="False" Visible="False">
  7. <HeaderStyle Width="30px"
  8. HorizontalAlign="Center" VerticalAlign="Middle" />
  9. <ItemStyle Width="30px" HorizontalAlign="Center"
  10. VerticalAlign="Middle" />
  11. <ItemTemplate>
  12.  
  13. <asp:Label ID="lblFileType" runat="server"
  14. Text='<%# Eval("FileType") %>'></asp:Label>
  15. </ItemTemplate>
  16. <EditItemTemplate>
  17. <asp:DropDownList ID="ddlType"
  18. runat="server" DataSource='<%# LoadFileTypes() %>'
  19. DataTextField="FileTypeCode" DataValueField="FileTypeCode"
  20. OnSelectedIndexChanged="ddlType_SelectedIndexChanged"></asp:DropDownList>
  21. </EditItemTemplate>
  22. </asp:TemplateField>
  23. .....
  24. </asp:GridView>
  25.  
  26.  
  27. I need to process the values of this Gridview cells inside in this method:
  28. private void UpdateRelatedFiles(Int32 ideaId, Int32 userId, Int32 langId)
  29. {
  30. ....
  31. RetrieveTempData();
  32. LoadFileGrid(true);
  33.  
  34. foreach (GridViewRow gr in gdvFiles.Rows)
  35. {
  36. id = ((HtmlInputCheckBox)gr.Cells[0].Controls[1]).Value;
  37. fileId = Convert.ToInt32(id);
  38. fname = gr.Cells[1].Text;
  39. ftype = gr.Cells[2].Text;<<<--- STRING VALUE IS EMPTY
  40. fsize = gr.Cells[3].Text;
  41. fpath = gr.Cells[4].Text;
  42. ....
  43. }
  44. ....
  45. }
  46.  
  47. private void RetrieveTempData()
  48. {
  49. ....
  50. dtFiles = GetTempData("Files");
  51. ....
  52. }
  53.  
  54. private DataTable GetTempData(string choice)
  55. {
  56. try
  57. {
  58. if (...)
  59. ....
  60. else if (choice == "Files")
  61. return (DataTable) Session["dtFiles"];
  62. }
  63. catch
  64. {
  65. return null;
  66. }
  67. return null;
  68. }
  69.  
  70. private void LoadFileGrid(bool colVisible)
  71. {
  72. if (dtFiles != null)
  73. {
  74. DataTable dtLocal = GetTempData("Files");
  75. if (dtLocal != null)
  76. gridview1.DataSource = dtLocal;
  77. else
  78. gridview1.DataSource = dtFiles;
  79. ChangeGridviewColumnVisibility(colVisible, gridview1, "Files",
  80. true);
  81. gridview1.DataBind();
  82. }
  83. }
  84.  
  85. private void ChangeGridviewColumnVisibility(bool visible, GridView
  86. gdvLocal, string section, bool isUpdate)
  87. {
  88.  
  89. for (int x = 0; x < gdvLocal.Columns.Count; x++)
  90. {
  91. if (visible)
  92. {
  93. if (gdvLocal.Columns[x].HeaderText == "DocumentID" &&
  94. isUpdate)
  95. gdvLocal.Columns[x].Visible = visible;
  96. else
  97. gdvLocal.Columns[x].Visible = visible;
  98. }
  99. else if (!visible)
  100. {
  101. if (x 1 && x < gdvLocal.Columns.Count - 1)
  102. gdvLocal.Columns[x].Visible = visible;
  103. }
  104. }
  105. }
  106.  
  107.  
--
MCP Year 2005, Philippines
Oct 11 '06 #1
0 2356

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jason | last post by:
Pardon my ignorance on this. The below code works, except, when I edit a record and update the two drop downs take the first entry in the dropdownlist if not selected. I'd also like the dropdown to...
1
by: CorporateCoder | last post by:
Hi, I am trying to bind the selected value of a databound dropdown box in a databound gridview control to the value being displayed in the template column the dropdown box has been added to. ...
0
by: Managed Code | last post by:
Hello, I have a status and definition table. The status table's current status field relates the ID field of the definition table. I am trying to retrieve the definitions that are associated...
3
by: podi | last post by:
Hi, I just wonder if there is a way to set a selected item in dropdown list which items are retreived from database without touching c# code ? I mean, i have in gridview, in edit mode one...
0
by: landesjoe | last post by:
Hi, here's my problem in short: Text boxes in gridview don't seem to hold their value if the column's .Visible property is changed back and forth. I've got a form with a gridview populated from...
0
by: sgtmarcjones | last post by:
How do I access a dropdownlist that is nested within a Formview ItemTemplate Gridview Template? I want to see a label (lgbTimeKeep ! TextValue of ddlName dropdownlist) instead of a dropdownlist...
0
by: dayiku | last post by:
I am trying to retrieve values from a boundfield in a detailsview. protected void BtnViewDetails_Click(object sender, EventArgs e) { // get the gridviewrow from the sender so we...
6
by: Ahmedhussain | last post by:
Hi there, I m doing work on a gridview and Im getting an error: A potentially dangerous Request.Form value was detected from the client (ctl00$Content$GridView1$ctl03$TextBox1="<span...
4
by: justice750 | last post by:
Hi All, I am using a FormView control. The allows me to update records in the database. However, when a database field is null I can not update the field on the form. It works fine when the field...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.