By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,176 Members | 1,071 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,176 IT Pros & Developers. It's quick & easy.

Can't get value of TemplateColumn in Editable DataGrid

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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" <Ca*************@discussions.microsoft.com> skrev i
meddelandet news:FC**********************************@microsof t.com...
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

Nov 19 '05 #2

P: n/a
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.Data Item,
"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" <Ca*************@discussions.microsoft.com> skrev i
meddelandet news:FC**********************************@microsof t.com...
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


Nov 19 '05 #3

P: n/a
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" <Ca*************@discussions.microsoft.com> skrev i
meddelandet news:F7**********************************@microsof t.com...
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.Data Item,
"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" <Ca*************@discussions.microsoft.com> skrev i
meddelandet news:FC**********************************@microsof t.com...
>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


Nov 19 '05 #4

P: n/a
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" <Ca*************@discussions.microsoft.com> skrev i
meddelandet news:F7**********************************@microsof t.com...
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.Data Item,
"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" <Ca*************@discussions.microsoft.com> skrev i
meddelandet news:FC**********************************@microsof t.com...
>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


Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.