473,396 Members | 2,099 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,396 software developers and data experts.

Problem Retrieving Cell Value From Datagrid

Hi All

Using Delphi 2006 developer - C# Project

I have the following 2 event handlers for the datagrid - see botton of
page
Both events will fire off correctly but i have a problem collecting the
correct data in teh Update event - I have noted the problem in the
event handler

protected void Livery_DeleteCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string LLivery = e.Item.Cells[1].Text;
string LLeadTime = e.Item.Cells[2].Text;
int LRow = e.Item.ItemIndex;

// If I step through this I can see the values of the cells of the
row highlighted when I press the delete button
}

protected void Livery_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string LLivery = e.Item.Cells[1].Text;
string LLeadTime = e.Item.Cells[2].Text;
int LRow = e.Item.ItemIndex;

// If I step through this the values of e.Item.Cells[1].Text and
// e.Item.Cells[2].Text are blank. I could understand if the
// value contained the old (pre-update) values or the
// new (post-update) values but the fields are blank ?????
// e.Item.ItemIndex is showing the correct row index
}

Can anyone advise me why this is so and if so how do I rectify the
situation.

Many thanks in advance for assistance offered

Iain

<asp:datagrid id="Livery" runat="server"
allowsorting="True"
EnableViewState="true"
itemstyle-verticalalign="top"
headerstyle-font-bold="true"
headerstyle-forecolor="white"
headerstyle-backcolor="black"
autogeneratecolumns="false" font-size="8pt"
cellpadding="5"
width="92%"
onsortcommand="Livery_SortCommand"
ondeletecommand="Livery_DeleteCommand"
oneditcommand="Livery_EditCommand"
onupdatecommand="Livery_UpdateCommand"
oncancelcommand="Livery_CancelCommand">
<EditItemStyle borderstyle="Dashed"
bordercolor="#0000C0"
backcolor="#FFFFC0">
</EditItemStyle>
<ItemStyle verticalalign="Top">
</ItemStyle>
<HeaderStyle font-bold="True"
forecolor="White"
backcolor="Black">
</HeaderStyle>
<Columns>
<ASP:EditCommandColumn
buttontype="PushButton"
updatetext="Update"
headertext="Edit"
canceltext="Cancel"
edittext="Edit">
</ASP:EditCommandColumn>
<ASP:BoundColumn datafield="LIVNAME"
headertext="Livery Name">
</ASP:BoundColumn>
<ASP:BoundColumn datafield="LEADTIME"
headertext="Lead Time">
</ASP:BoundColumn>
<ASP:ButtonColumn text="Delete"
buttontype="PushButton"
headertext="Delete"
commandname="Delete">
</ASP:ButtonColumn>
</Columns>
</asp:datagrid>

Jan 20 '07 #1
2 1970
hi iain,
you probably have to dig in to the controls property of the cell in
question.
Control.Text only works if there is plain text with no server controls
inside the control.
in your case, i presume the edit mode of the datagrid has rendered some
textboxes instead.
you probably want something like this:

// if the textbox is the first control in the cell in edit mode...
string LLivery = (e.Item.Cells[1].Controls[0] as TextBox).Text;

// or you can use FindControl()
string LLivery = (e.Item.Cells[1].FindControl("txtLivery") as TextBox).Text;

hope this does it for you
tim

"Iain" <Em**************@gmail.comwrote in message
news:11**********************@q2g2000cwa.googlegro ups.com...
Hi All

Using Delphi 2006 developer - C# Project

I have the following 2 event handlers for the datagrid - see botton of
page
Both events will fire off correctly but i have a problem collecting the
correct data in teh Update event - I have noted the problem in the
event handler

protected void Livery_DeleteCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string LLivery = e.Item.Cells[1].Text;
string LLeadTime = e.Item.Cells[2].Text;
int LRow = e.Item.ItemIndex;

// If I step through this I can see the values of the cells of the
row highlighted when I press the delete button
}

protected void Livery_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string LLivery = e.Item.Cells[1].Text;
string LLeadTime = e.Item.Cells[2].Text;
int LRow = e.Item.ItemIndex;

// If I step through this the values of e.Item.Cells[1].Text and
// e.Item.Cells[2].Text are blank. I could understand if the
// value contained the old (pre-update) values or the
// new (post-update) values but the fields are blank ?????
// e.Item.ItemIndex is showing the correct row index
}

Can anyone advise me why this is so and if so how do I rectify the
situation.

Many thanks in advance for assistance offered

Iain

<asp:datagrid id="Livery" runat="server"
allowsorting="True"
EnableViewState="true"
itemstyle-verticalalign="top"
headerstyle-font-bold="true"
headerstyle-forecolor="white"
headerstyle-backcolor="black"
autogeneratecolumns="false" font-size="8pt"
cellpadding="5"
width="92%"
onsortcommand="Livery_SortCommand"
ondeletecommand="Livery_DeleteCommand"
oneditcommand="Livery_EditCommand"
onupdatecommand="Livery_UpdateCommand"
oncancelcommand="Livery_CancelCommand">
<EditItemStyle borderstyle="Dashed"
bordercolor="#0000C0"
backcolor="#FFFFC0">
</EditItemStyle>
<ItemStyle verticalalign="Top">
</ItemStyle>
<HeaderStyle font-bold="True"
forecolor="White"
backcolor="Black">
</HeaderStyle>
<Columns>
<ASP:EditCommandColumn
buttontype="PushButton"
updatetext="Update"
headertext="Edit"
canceltext="Cancel"
edittext="Edit">
</ASP:EditCommandColumn>
<ASP:BoundColumn datafield="LIVNAME"
headertext="Livery Name">
</ASP:BoundColumn>
<ASP:BoundColumn datafield="LEADTIME"
headertext="Lead Time">
</ASP:BoundColumn>
<ASP:ButtonColumn text="Delete"
buttontype="PushButton"
headertext="Delete"
commandname="Delete">
</ASP:ButtonColumn>
</Columns>
</asp:datagrid>
Jan 20 '07 #2
Hi Tim

Thanks for your assistance.
The string LLivery = (e.Item.Cells[1].Controls[0] as TextBox).Text;
appears to work well.
Much appreciated

Iain

Jan 22 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Billy Jacobs | last post by:
I have created a DataGridColumnDatePicker Component so that I can put a datetimepicker control in my datagrid. It almost works. When I put my mouse in the cell it changes to a datetimepicker...
2
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell...
9
by: Morten | last post by:
Hi! I have a problem displaying some values in a datagrid. I have an array that consists of a number of objects. Each object has 2 properties: Name and a list of web addresses. (e.g: Name:...
3
by: Sunil Sabir | last post by:
Dear All, I have a datagrid which displays the column of Names of doctors.When I use e.item.cell(5).Text. I see the name of two doctors instead of one.In the database the doctors name are: ...
7
by: Girish | last post by:
OK.. phew. Playing with data grids for the past few days has been fun and a huge learning experience.. My problem. I have a requirement to display a gird with a gird. Within the embedded grid,...
3
by: Maria Anthonsen | last post by:
I'm using HitTest to get a value from the cells into a textbox. I have put the HitTest code into the MouseDown-event, and everything is working except one thing. When I start the program the value...
3
by: JJ | last post by:
I have a datagrid on my form that displays its data from various tables within a specified dataset. That all works correclty. However, when one cell is selected prior to changed the displayed...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
1
by: Ahmed Yasser | last post by:
Hi all, i have a problem with the datagridview sorting, the problem is a bit complicated so i hope i can describe in the following steps: 1. i have a datagridview with two columns...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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,...

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.