473,785 Members | 2,761 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3253
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.m icrosoft.com> skrev i
meddelandet news:FC******** *************** ***********@mic rosoft.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:TemplateCo lumn HeaderText="Sta tistik<br>grupp e">
<ItemTemplate >
<asp:Label id=Label1 runat="server" Text='<%#
DataBinder.Eval (Container, "DataItem.m_ake yp1") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTempla te>
<asp:DropDownLi st id=ddlM_akeyp1 runat="server" CssClass="Entry field"
SelectedIndex=' <%# GetM_akeyp1((st ring)DataBinder .Eval(Container .DataItem,
"m_akeyp1") ) %>' DataSource="<%# GetM_akeyp1List ()%>" datatextfield=" text"
datavaluefield= "value">
</asp:DropDownLis t>
</EditItemTemplat e>
</asp:TemplateCol umn>

"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.m icrosoft.com> skrev i
meddelandet news:FC******** *************** ***********@mic rosoft.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.FindC ontrol("ddlM_ak eyp1"),
DropDownList).S electedItem.Tex t

Hope it works!

/Lars Netzel

"Carlo Marchesoni" <Ca************ *@discussions.m icrosoft.com> skrev i
meddelandet news:F7******** *************** ***********@mic rosoft.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:TemplateCo lumn HeaderText="Sta tistik<br>grupp e">
<ItemTemplate >
<asp:Label id=Label1 runat="server" Text='<%#
DataBinder.Eval (Container, "DataItem.m_ake yp1") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTempla te>
<asp:DropDownLi st id=ddlM_akeyp1 runat="server" CssClass="Entry field"
SelectedIndex=' <%# GetM_akeyp1((st ring)DataBinder .Eval(Container .DataItem,
"m_akeyp1") ) %>' DataSource="<%# GetM_akeyp1List ()%>" datatextfield=" text"
datavaluefield= "value">
</asp:DropDownLis t>
</EditItemTemplat e>
</asp:TemplateCol umn>

"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.m icrosoft.com> skrev i
meddelandet news:FC******** *************** ***********@mic rosoft.com...
>I have an editable Datagrid and some columns (4 and 5) are
>TemplateColumn s
> (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 "FindContro l"
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.FindC ontrol("ddlM_ak eyp1"),
DropDownList).S electedItem.Tex t

Hope it works!

/Lars Netzel

"Carlo Marchesoni" <Ca************ *@discussions.m icrosoft.com> skrev i
meddelandet news:F7******** *************** ***********@mic rosoft.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:TemplateCo lumn HeaderText="Sta tistik<br>grupp e">
<ItemTemplate >
<asp:Label id=Label1 runat="server" Text='<%#
DataBinder.Eval (Container, "DataItem.m_ake yp1") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTempla te>
<asp:DropDownLi st id=ddlM_akeyp1 runat="server" CssClass="Entry field"
SelectedIndex=' <%# GetM_akeyp1((st ring)DataBinder .Eval(Container .DataItem,
"m_akeyp1") ) %>' DataSource="<%# GetM_akeyp1List ()%>" datatextfield=" text"
datavaluefield= "value">
</asp:DropDownLis t>
</EditItemTemplat e>
</asp:TemplateCol umn>

"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.m icrosoft.com> skrev i
meddelandet news:FC******** *************** ***********@mic rosoft.com...
>I have an editable Datagrid and some columns (4 and 5) are
>TemplateColumn s
> (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
2033
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 DataGrid. 1. If I try to bind the second datasource to the dropdown I get An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll. 2. If I comment that line out it displays always the dropdown. I want it to...
1
1910
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 = '<%# ddlUser5Bind() %>' Runat =server> </asp:DropDownList> </EditItemTemplate>
1
10930
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 my datalist has an id of "Datagrid3". dgChild comes back with "Nothing" while debugging. Here is my code in the itemdatabound event for the datalist: <code>
3
2507
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" AutoEventWireup="false" Codebehind="Search.aspx.vb" Inherits="PROJECT.WebForm1"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <title>WebForm1</title>
2
2023
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 show the current value in edit mode. I'm sure this is a common question. I've reviewed several related post and tried them out to no avial. Some of the offerings in listgroup look right on, but are not clear on where to handle the suggested...
0
1399
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. Question #1: In the Add button Command Event I am trying to access the Text value of the TextBox in the other Footer columns. However, inside the Event, the TextBox.Text values are all empty strings, even if they had data typed into them. Is this a...
0
1612
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 depending on various conditions. Column items are typical Labels in <ItemTemplate> and TextBoxes in <EditItemTemplate> forms. When the user clicks Edit, I would like to do the following:
0
1855
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 the gridview to fire on pageload (including postbacks) because I need to change the value of the textbox at each of the dropdownlists autopostback event. I am using the OnItemDataBound event of the gridview to grab the selectedvalue of the...
2
2994
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 CartTable programmatically with rows from a database binded datagrid.. i cant figure out what is wroooong! hehe thanks for helping here is my code: TABLE CODE (in the page_load): If Session("shop_cart") Is Nothing Then
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9481
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10155
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8978
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.