Can't get value of TemplateColumn in Editable DataGrid

G

Guest

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
 
L

Lars Netzel

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
 
G

Guest

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 said:
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 said:
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
 
L

Lars Netzel

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 said:
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 said:
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 said:
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
 
G

Guest

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 said:
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 said:
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 said:
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" <[email protected]> skrev i
meddelandet 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
 

Ask a Question

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top