470,562 Members | 2,312 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,562 developers. It's quick & easy.

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 2229

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by livre | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.