Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Can't get value of TemplateColumn in Editable DataGrid

Reply
Thread Tools

Can't get value of TemplateColumn in Editable DataGrid

 
 
=?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?=
Guest
Posts: n/a
 
      01-06-2005
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
 
Reply With Quote
 
 
 
 
Lars Netzel
Guest
Posts: n/a
 
      01-06-2005
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" <(E-Mail Removed)> skrev i
meddelandet news:(E-Mail Removed)...
>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



 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?=
Guest
Posts: n/a
 
      01-06-2005
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>
<aspropDownList 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">
</aspropDownList>
</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" <(E-Mail Removed)> skrev i
> meddelandet news:(E-Mail Removed)...
> >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

>
>
>

 
Reply With Quote
 
Lars Netzel
Guest
Posts: n/a
 
      01-06-2005
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" <(E-Mail Removed)> skrev i
meddelandet news:(E-Mail Removed)...
> 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>
> <aspropDownList 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">
> </aspropDownList>
> </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" <(E-Mail Removed)> skrev i
>> meddelandet news:(E-Mail Removed)...
>> >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

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?=
Guest
Posts: n/a
 
      01-07-2005
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" <(E-Mail Removed)> skrev i
> meddelandet news:(E-Mail Removed)...
> > 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>
> > <aspropDownList 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">
> > </aspropDownList>
> > </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" <(E-Mail Removed)> skrev i
> >> meddelandet news:(E-Mail Removed)...
> >> >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
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Read Value from DropDownList in TemplateColumn? Vagabond Software ASP .Net 0 06-08-2006 10:12 PM
How to get the editable textbox value from GridView in my code-beh =?Utf-8?B?U0RSb3k=?= ASP .Net 0 04-26-2006 07:01 PM
DataGrid EditItemCommand : must click twice to make DataGrid Editable Diane ASP .Net Datagrid Control 5 11-09-2005 09:54 AM
DataGrid/ TemplateColumn/ HeaderTemplate / Preserve Value in Postb codputer ASP .Net Datagrid Control 0 12-31-2004 07:27 PM
Make DataGrid TemplateColumn read-only in code Bob ASP .Net 0 07-09-2003 05:56 PM



Advertisments