Can't get value of TemplateColumn in Editable DataGrid

Discussion in 'ASP .Net' started by =?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?=, Jan 6, 2005.

  1. I have an editable Datagrid and some columns (4 and 5) are TemplateColumns
    (because I have DropDownLists there).
    Everything works fine except that if I want to retrieve the values (that I
    can see visually) from the DataGrid with the following loop the Values of the
    TemplateColumns are returned as blank - what am I doing wrong ?:
    foreach (DataGridItem dgi in dgrDu01.Items)
    {
    string myvalue1 = dgi.Cells[1].Text; //ok
    etc..
    string myvalue = dgi.Cells[4].Text; // returns blank, although I have a
    value
    }
    Thanks for your help
     
    =?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?=, Jan 6, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?=

    Lars Netzel Guest

    Are you having an EditItemTemple in you TempleColumn or just ItemTemplate?
    Maybe this is to basic but I have to ask cause oif you wrote the
    templatecolumn yourself It's easy to forget.. whereas if you startoff with a
    bound column and then convert it to a templatecolumn it creates both type
    automatically.

    /Lars NetzeL


    "Carlo Marchesoni" <> skrev i
    meddelandet news:...
    >I have an editable Datagrid and some columns (4 and 5) are TemplateColumns
    > (because I have DropDownLists there).
    > Everything works fine except that if I want to retrieve the values (that I
    > can see visually) from the DataGrid with the following loop the Values of
    > the
    > TemplateColumns are returned as blank - what am I doing wrong ?:
    > foreach (DataGridItem dgi in dgrDu01.Items)
    > {
    > string myvalue1 = dgi.Cells[1].Text; //ok
    > etc..
    > string myvalue = dgi.Cells[4].Text; // returns blank, although I have a
    > value
    > }
    > Thanks for your help
     
    Lars Netzel, Jan 6, 2005
    #2
    1. Advertising

  3. It's true that I wrote it myself (well, I copied it from a sample I found).
    Here is the snippet of the aspx file:
    <asp:TemplateColumn HeaderText="Statistik<br>gruppe">
    <ItemTemplate>
    <asp:Label id=Label1 runat="server" Text='<%#
    DataBinder.Eval(Container, "DataItem.m_akeyp1") %>'>
    </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:DropDownList id=ddlM_akeyp1 runat="server" CssClass="Entryfield"
    SelectedIndex='<%# GetM_akeyp1((string)DataBinder.Eval(Container.DataItem,
    "m_akeyp1")) %>' DataSource="<%#GetM_akeyp1List()%>" datatextfield="text"
    datavaluefield="value">
    </asp:DropDownList>
    </EditItemTemplate>
    </asp:TemplateColumn>



    "Lars Netzel" wrote:

    > Are you having an EditItemTemple in you TempleColumn or just ItemTemplate?
    > Maybe this is to basic but I have to ask cause oif you wrote the
    > templatecolumn yourself It's easy to forget.. whereas if you startoff with a
    > bound column and then convert it to a templatecolumn it creates both type
    > automatically.
    >
    > /Lars NetzeL
    >
    >
    > "Carlo Marchesoni" <> skrev i
    > meddelandet news:...
    > >I have an editable Datagrid and some columns (4 and 5) are TemplateColumns
    > > (because I have DropDownLists there).
    > > Everything works fine except that if I want to retrieve the values (that I
    > > can see visually) from the DataGrid with the following loop the Values of
    > > the
    > > TemplateColumns are returned as blank - what am I doing wrong ?:
    > > foreach (DataGridItem dgi in dgrDu01.Items)
    > > {
    > > string myvalue1 = dgi.Cells[1].Text; //ok
    > > etc..
    > > string myvalue = dgi.Cells[4].Text; // returns blank, although I have a
    > > value
    > > }
    > > Thanks for your help

    >
    >
    >
     
    =?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?=, Jan 6, 2005
    #3
  4. =?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?=

    Lars Netzel Guest

    Okay!

    I should write this instead, use FindControl and Cast to the proper type!

    string myvalue = Ctype(dgi.FindControl("ddlM_akeyp1"),
    DropDownList).SelectedItem.Text

    Hope it works!

    /Lars Netzel



    "Carlo Marchesoni" <> skrev i
    meddelandet news:...
    > It's true that I wrote it myself (well, I copied it from a sample I
    > found).
    > Here is the snippet of the aspx file:
    > <asp:TemplateColumn HeaderText="Statistik<br>gruppe">
    > <ItemTemplate>
    > <asp:Label id=Label1 runat="server" Text='<%#
    > DataBinder.Eval(Container, "DataItem.m_akeyp1") %>'>
    > </asp:Label>
    > </ItemTemplate>
    > <EditItemTemplate>
    > <asp:DropDownList id=ddlM_akeyp1 runat="server" CssClass="Entryfield"
    > SelectedIndex='<%# GetM_akeyp1((string)DataBinder.Eval(Container.DataItem,
    > "m_akeyp1")) %>' DataSource="<%#GetM_akeyp1List()%>" datatextfield="text"
    > datavaluefield="value">
    > </asp:DropDownList>
    > </EditItemTemplate>
    > </asp:TemplateColumn>
    >
    >
    >
    > "Lars Netzel" wrote:
    >
    >> Are you having an EditItemTemple in you TempleColumn or just
    >> ItemTemplate?
    >> Maybe this is to basic but I have to ask cause oif you wrote the
    >> templatecolumn yourself It's easy to forget.. whereas if you startoff
    >> with a
    >> bound column and then convert it to a templatecolumn it creates both type
    >> automatically.
    >>
    >> /Lars NetzeL
    >>
    >>
    >> "Carlo Marchesoni" <> skrev i
    >> meddelandet news:...
    >> >I have an editable Datagrid and some columns (4 and 5) are
    >> >TemplateColumns
    >> > (because I have DropDownLists there).
    >> > Everything works fine except that if I want to retrieve the values
    >> > (that I
    >> > can see visually) from the DataGrid with the following loop the Values
    >> > of
    >> > the
    >> > TemplateColumns are returned as blank - what am I doing wrong ?:
    >> > foreach (DataGridItem dgi in dgrDu01.Items)
    >> > {
    >> > string myvalue1 = dgi.Cells[1].Text; //ok
    >> > etc..
    >> > string myvalue = dgi.Cells[4].Text; // returns blank, although I
    >> > have a
    >> > value
    >> > }
    >> > Thanks for your help

    >>
    >>
    >>
     
    Lars Netzel, Jan 6, 2005
    #4
  5. Thank you for giving me the right way to look for. I have to "FindControl"
    the Label and cast to the Label and now it works.

    "Lars Netzel" wrote:

    > Okay!
    >
    > I should write this instead, use FindControl and Cast to the proper type!
    >
    > string myvalue = Ctype(dgi.FindControl("ddlM_akeyp1"),
    > DropDownList).SelectedItem.Text
    >
    > Hope it works!
    >
    > /Lars Netzel
    >
    >
    >
    > "Carlo Marchesoni" <> skrev i
    > meddelandet news:...
    > > It's true that I wrote it myself (well, I copied it from a sample I
    > > found).
    > > Here is the snippet of the aspx file:
    > > <asp:TemplateColumn HeaderText="Statistik<br>gruppe">
    > > <ItemTemplate>
    > > <asp:Label id=Label1 runat="server" Text='<%#
    > > DataBinder.Eval(Container, "DataItem.m_akeyp1") %>'>
    > > </asp:Label>
    > > </ItemTemplate>
    > > <EditItemTemplate>
    > > <asp:DropDownList id=ddlM_akeyp1 runat="server" CssClass="Entryfield"
    > > SelectedIndex='<%# GetM_akeyp1((string)DataBinder.Eval(Container.DataItem,
    > > "m_akeyp1")) %>' DataSource="<%#GetM_akeyp1List()%>" datatextfield="text"
    > > datavaluefield="value">
    > > </asp:DropDownList>
    > > </EditItemTemplate>
    > > </asp:TemplateColumn>
    > >
    > >
    > >
    > > "Lars Netzel" wrote:
    > >
    > >> Are you having an EditItemTemple in you TempleColumn or just
    > >> ItemTemplate?
    > >> Maybe this is to basic but I have to ask cause oif you wrote the
    > >> templatecolumn yourself It's easy to forget.. whereas if you startoff
    > >> with a
    > >> bound column and then convert it to a templatecolumn it creates both type
    > >> automatically.
    > >>
    > >> /Lars NetzeL
    > >>
    > >>
    > >> "Carlo Marchesoni" <> skrev i
    > >> meddelandet news:...
    > >> >I have an editable Datagrid and some columns (4 and 5) are
    > >> >TemplateColumns
    > >> > (because I have DropDownLists there).
    > >> > Everything works fine except that if I want to retrieve the values
    > >> > (that I
    > >> > can see visually) from the DataGrid with the following loop the Values
    > >> > of
    > >> > the
    > >> > TemplateColumns are returned as blank - what am I doing wrong ?:
    > >> > foreach (DataGridItem dgi in dgrDu01.Items)
    > >> > {
    > >> > string myvalue1 = dgi.Cells[1].Text; //ok
    > >> > etc..
    > >> > string myvalue = dgi.Cells[4].Text; // returns blank, although I
    > >> > have a
    > >> > value
    > >> > }
    > >> > Thanks for your help
    > >>
    > >>
    > >>

    >
    >
    >
     
    =?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?=, Jan 7, 2005
    #5
    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. Bob
    Replies:
    0
    Views:
    631
  2. =?Utf-8?B?U0RSb3k=?=
    Replies:
    0
    Views:
    5,437
    =?Utf-8?B?U0RSb3k=?=
    Apr 26, 2006
  3. Vagabond Software

    Read Value from DropDownList in TemplateColumn?

    Vagabond Software, Jun 8, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    539
    Vagabond Software
    Jun 8, 2006
  4. codputer
    Replies:
    0
    Views:
    116
    codputer
    Dec 31, 2004
  5. Diane
    Replies:
    5
    Views:
    291
    alvinz_c
    Nov 9, 2005
Loading...

Share This Page