No Value: DropDownlist in EditItemTemplate Gridview Problem

Discussion in 'ASP .Net Web Controls' started by den 2005, Oct 11, 2006.

  1. den 2005

    den 2005 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
     
    den 2005, Oct 11, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Tkg=?=
    Replies:
    2
    Views:
    29,391
    =?Utf-8?B?Tkg=?=
    Mar 27, 2006
  2. WT
    Replies:
    2
    Views:
    4,605
  3. =?Utf-8?B?ZGVuIDIwMDU=?=

    No Value: DropDownlist in EditItemTemplate Gridview Problem

    =?Utf-8?B?ZGVuIDIwMDU=?=, Oct 11, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    549
    =?Utf-8?B?ZGVuIDIwMDU=?=
    Oct 11, 2006
  4. Jeff
    Replies:
    0
    Views:
    398
  5. den 2005

    DropDownlist in EditItemTemplate Gridview Problem

    den 2005, Oct 11, 2006, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    311
    Antoine Griffard
    Oct 11, 2006
Loading...

Share This Page