473,763 Members | 5,396 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

No Value: DropDownlist in EditItemTemplat e Gridview Problem

Hi everybody,

I created a Gridview with a TemplateField and there is Label control in
ItemTemplate and a DropdownList control in EditItemTemplat e, 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 2394

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

Similar topics

2
2023
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 show the current value in edit mode. I'm sure this is a common question. I've reviewed several related post and tried them out to no avial. Some of the offerings in listgroup look right on, but are not clear on where to handle the suggested...
1
14314
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. Both the grid and the dropdown box are retrieving and displaying data fine, I just cant bind the two together. I followed the instructions in the help document called 'Walkthrough: Displaying a Drop-Down List While Editing in the GridView Web...
0
1601
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 only with the master_id for the status table's current status. After having some trouble databinding I found a solution using a hidden label to save the value I need for my select parameter. The error I am receiving is 'ddlStatus' has a...
3
6606
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 dropdownlist which selected value should be the same as a label text from normal view mode <EditItemTemplate> <asp:DropDownList ID="ddlGrdvFrequency" runat="server" DataTextField="Frequency"
0
2436
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 a data view (which in turn is loaded from a manually setup DataTable for testing purposes). One of the columns in the grid is a checkbox that's tied to an event handler that'll change the .Visible property of a column with a text box. That text...
0
5962
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 in the FormView ItemTemplate Nested Gridview ddlName ItemTemplate. My label is named lgvTimeKeep and the dropdownlist name is ddlName. Thanks!
0
4629
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 can get the datakey we need Button btnDetails = sender as Button; GridViewRow row = (GridViewRow)btnDetails.NamingContainer; DropDownList ddl = ((DropDownList)dvVehicleDetail.FindControl("DropdownList1"));
6
4280
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 class='txtColo...") Im using an access database. and when ever I try to update this it doesnt work. <%@ Page Language="C#" MasterPageFile="Mysite.master" Title="Untitled Page" %> <script runat = "server"> protected void Page_Load(object sender,...
4
2907
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 is not a null value. I am not using any code behind (C#) to bind the data or manipulate the data. I have read that when there is a null value in the database that there is no record in the "dataset". Can anyone show me how to bind a value in the...
0
9564
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10002
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2794
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.