473,395 Members | 1,471 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Can't get value of TemplateColumn in Editable DataGrid

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
4 3236
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kilic Beg via .NET 247 | last post by:
Hi, I am having trouble adding a dropdown to DataGrid at runtime. I create all boundColumns and the TemplateColumn for the dropdown at runtime. The dropdown has a different datasource then the...
1
by: Biva | last post by:
Hello, I have a drop down list control in a datagrid. I can't seem to populate the control. Here is what my code looks like: <EditItemTemplate> <asp:DropDownList ID= "ddlUser5" DataSource =...
1
by: bill yeager | last post by:
I have a datagrid control within a datalist control. When I try and do a "Find" on the control, the object comes back with nothing and then my pgm crashes. I am 100% sure that my datagird inside...
3
by: Rob Rogers | last post by:
I have an ASP.NET datagrid that loads an image. I would like to load one image if the value in my SQL table is true and another if it is false. Here is my code. <%@ Page Language="vb"...
2
by: jason | last post by:
Pardon my ignorance on this. The below code works, except, when I edit a record and update the two drop downs take the first entry in the dropdownlist if not selected. I'd also like the dropdown to...
0
by: jason | last post by:
Hello everyone. I am trying to write some custom command events into a DataGrid. The command that is currently giving me trouble is an "Add" custom command in the footer of a template column. ...
0
by: Jeff User | last post by:
I have my datagrid running pretty much with a EditCommandColumn and some TemplateColumn columns. There are two types of appearance changes I would like to make programatically from my C# code...
0
by: rmccinc | last post by:
I have a dropdownlist in a datagrid and it has autopostback set to true. I need to get the new value of that dropdown to fill a textbox in the same datagrid row. I have set the databind event on...
2
by: ismaelf | last post by:
i have a textbox in a template column in a datagrid, it displays the initial value of the row, but when i change it remains with the original value (it doesnt get the new value..) i fill the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.