No Value: DropDownlist in EditItemTemplate Gridview Problem

Discussion in 'Microsoft ASP .NET' started by Guest, Oct 11, 2006.

  1. Guest

    Guest Guest

    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

    Code:
    <asp:GridView ID="gdvFiles" runat="server"
    AutoGenerateColumns="False" ShowHeader="False" Width="649px"
    OnRowEditing="gdvFiles_RowEditing" OnRowUpdating="gdvFiles_RowUpdating">
    .....
    <asp:TemplateField HeaderText="FileType"
    ShowHeader="False" Visible="False">
    <HeaderStyle Width="30px"
    HorizontalAlign="Center" VerticalAlign="Middle" />
    <ItemStyle Width="30px" HorizontalAlign="Center"
    VerticalAlign="Middle" />
    <ItemTemplate>
    
    <asp:Label ID="lblFileType" runat="server"
    Text='<%# Eval("FileType") %>'></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:DropDownList ID="ddlType"
    runat="server" DataSource='<%# LoadFileTypes() %>'
    DataTextField="FileTypeCode" DataValueField="FileTypeCode"
    OnSelectedIndexChanged="ddlType_SelectedIndexChanged"></asp:DropDownList>
    </EditItemTemplate>
    </asp:TemplateField>
    .....
    </asp:GridView>
    
    
    I need to process the values of this Gridview cells inside in this method:
    private void UpdateRelatedFiles(Int32 ideaId, Int32 userId, Int32 langId)
    {
    ....
    RetrieveTempData();
    LoadFileGrid(true);
    
    foreach (GridViewRow gr in gdvFiles.Rows)
    {
    id = ((HtmlInputCheckBox)gr.Cells[0].Controls[1]).Value;
    fileId = Convert.ToInt32(id);
    fname = gr.Cells[1].Text;
    ftype = gr.Cells[2].Text;<<<--- STRING VALUE IS EMPTY
    fsize = gr.Cells[3].Text;
    fpath = gr.Cells[4].Text;
    ....
    }
    ....
    }
    
    private void RetrieveTempData()
    {
    ....
    dtFiles = GetTempData("Files");
    ....
    }
    
    private DataTable GetTempData(string choice)
    {
    try
    {
    if (...)
    ....
    else if (choice == "Files")
    return (DataTable) Session["dtFiles"];
    }
    catch
    {
    return null;
    }
    return null;
    }
    
    private void LoadFileGrid(bool colVisible)
    {
    if (dtFiles != null)
    {
    DataTable dtLocal = GetTempData("Files");
    if (dtLocal != null)
    gridview1.DataSource = dtLocal;
    else
    gridview1.DataSource = dtFiles;
    ChangeGridviewColumnVisibility(colVisible, gridview1, "Files",
    true);
    gridview1.DataBind();
    }
    }
    
    private void ChangeGridviewColumnVisibility(bool visible, GridView
    gdvLocal, string section, bool isUpdate)
    {
    
    for (int x = 0; x < gdvLocal.Columns.Count; x++)
    {
    if (visible)
    {
    if (gdvLocal.Columns[x].HeaderText == "DocumentID" &&
    isUpdate)
    gdvLocal.Columns[x].Visible = visible;
    else
    gdvLocal.Columns[x].Visible = visible;
    }
    else if (!visible)
    {
    if (x > 1 && x < gdvLocal.Columns.Count - 1)
    gdvLocal.Columns[x].Visible = visible;
    }
    }
    }
    
    
    --
    MCP Year 2005, Philippines
     
    Guest, Oct 11, 2006
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. George Durzi

    DropDownList in EditItemTemplate

    George Durzi, Sep 27, 2004, in forum: Microsoft ASP .NET
    Replies:
    1
    Views:
    345
    George Durzi
    Sep 27, 2004
  2. Guest
    Replies:
    0
    Views:
    424
    Guest
    Dec 23, 2005
  3. Guest
    Replies:
    0
    Views:
    824
    Guest
    Dec 29, 2005
  4. Guest
    Replies:
    2
    Views:
    1,450
    Guest
    Mar 27, 2006
  5. WT
    Replies:
    2
    Views:
    1,956
  6. Steve Hershoff
    Replies:
    2
    Views:
    635
    Steve Hershoff
    Apr 11, 2007
  7. Replies:
    1
    Views:
    369
  8. Jeff

    problem using DropDownList in EditItemTemplate

    Jeff, Nov 13, 2008, in forum: Microsoft ASP .NET
    Replies:
    0
    Views:
    212
Loading...