472,952 Members | 2,216 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,952 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>
  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>
  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);
  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. }
  47. private void RetrieveTempData()
  48. {
  49. ....
  50. dtFiles = GetTempData("Files");
  51. ....
  52. }
  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. }
  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. }
  85. private void ChangeGridviewColumnVisibility(bool visible, GridView
  86. gdvLocal, string section, bool isUpdate)
  87. {
  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. }
MCP Year 2005, Philippines
Oct 11 '06 #1
0 2321

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

Similar topics

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...
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. ...
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...
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...
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...
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...
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...
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...
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...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: Mushico | last post by:
How to calculate date of retirement from date of birth
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.