473,394 Members | 1,944 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,394 software developers and data experts.

DataGrid - Weird Update Command Problem

BW
Hello,

I am attempting to to take edited values from a datagrid control and update
the underlying database. Problem is that some of the edited values don quite
seem to make it to my update sub. My code is shown below. The values that
are not appearing are Cell(4) - sCompletion and Cell(5) - sNote. The other
values show up just fine.

What am I missing here?

Bernard

Dim iLogID As String = Convert.ToString(e.Item.Cells(0).Text)

Dim sEntry As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text

Dim sResp As String = CType(e.Item.Cells(3).Controls(1),
DropDownList).SelectedItem.Value

Dim sCompletion As String = CType(e.Item.Cells(4).Controls(0), TextBox).Text
'Now.Date.ToString

Dim sNote As String = CType(e.Item.Cells(5).Controls(0), TextBox).Text

If sNote = "" Then sNote = "*"

'Fill a string builder just to check values passed by DataGrid

Dim sb = New StringBuilder

sb.Append("LogItem = " & iLogID)

sb.Append("; EntryDate: " & sEntry)

sb.Append("; Responsible: " & sResp)

sb.Append("; Completion Date: " & sCompletion)

sb.Append("; Note: " & sNote)

Label1.Text = sb.ToString

================================================== ==============================

The DataGrid Code

================================================== ==============================

<asp:datagrid id="DataGrid1" runat="server" ForeColor="Black"
BorderColor="#999999" BorderStyle="None"
BorderWidth="1px" BackColor="White" CellPadding="3"
GridLines="Vertical" AutoGenerateColumns="False">
<FooterStyle BackColor="#CCCCCC"></FooterStyle>
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#000099"></SelectedItemStyle>
<AlternatingItemStyle BackColor="#CCCCCC"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="Black"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="LogID" ReadOnly="True"
HeaderText="LogID"></asp:BoundColumn>
<asp:BoundColumn DataField="LogItem" ReadOnly="True"
HeaderText="Log Item"></asp:BoundColumn>
<asp:BoundColumn DataField="LogDate" HeaderText="Entry"
DataFormatString="{0:MM-dd-yy}"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Resp">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.UserName") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="UserIDList" runat="server" Datasource="<%#
GetUserIDList() %>" DataTextField="UserName" DataValueField="UserID" />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="CompletionDate" HeaderText="Completed"
DataFormatString="{0:MM-dd-yy}"></asp:BoundColumn>
<asp:BoundColumn DataField="LogItemNote"
HeaderText="Note"></asp:BoundColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete"
CommandName="Delete"></asp:ButtonColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="Black"
BackColor="#999999"></PagerStyle>
</asp:datagrid>

Nov 19 '05 #1
1 1702
BW
Found it thanks to Scott Mitchell's book: "Asp.Net Data Web Controls Kick
Start."

Needed to assign OnEdi/Cancel/Update/Delete commands for the grid. Also
added postback check in page load event. If the page is posted back, fill
the grid. If not, do the update.

If Not IsPostBack() Then
FillGrid()
End If

Thanks Scott!
PS - Great Book!

Bernard
"BW" <bw*********@aegisadvisers.com> wrote in message
news:OP**************@TK2MSFTNGP10.phx.gbl...
Hello,

I am attempting to to take edited values from a datagrid control and
update the underlying database. Problem is that some of the edited values
don quite seem to make it to my update sub. My code is shown below. The
values that are not appearing are Cell(4) - sCompletion and Cell(5) -
sNote. The other values show up just fine.

What am I missing here?

Bernard

Dim iLogID As String = Convert.ToString(e.Item.Cells(0).Text)

Dim sEntry As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text

Dim sResp As String = CType(e.Item.Cells(3).Controls(1),
DropDownList).SelectedItem.Value

Dim sCompletion As String = CType(e.Item.Cells(4).Controls(0),
TextBox).Text 'Now.Date.ToString

Dim sNote As String = CType(e.Item.Cells(5).Controls(0), TextBox).Text

If sNote = "" Then sNote = "*"

'Fill a string builder just to check values passed by DataGrid

Dim sb = New StringBuilder

sb.Append("LogItem = " & iLogID)

sb.Append("; EntryDate: " & sEntry)

sb.Append("; Responsible: " & sResp)

sb.Append("; Completion Date: " & sCompletion)

sb.Append("; Note: " & sNote)

Label1.Text = sb.ToString

================================================== ==============================

The DataGrid Code

================================================== ==============================

<asp:datagrid id="DataGrid1" runat="server" ForeColor="Black"
BorderColor="#999999" BorderStyle="None"
BorderWidth="1px" BackColor="White" CellPadding="3"
GridLines="Vertical" AutoGenerateColumns="False">
<FooterStyle BackColor="#CCCCCC"></FooterStyle>
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#000099"></SelectedItemStyle>
<AlternatingItemStyle BackColor="#CCCCCC"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="Black"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="LogID" ReadOnly="True"
HeaderText="LogID"></asp:BoundColumn>
<asp:BoundColumn DataField="LogItem" ReadOnly="True"
HeaderText="Log Item"></asp:BoundColumn>
<asp:BoundColumn DataField="LogDate" HeaderText="Entry"
DataFormatString="{0:MM-dd-yy}"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Resp">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.UserName") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="UserIDList" runat="server" Datasource="<%#
GetUserIDList() %>" DataTextField="UserName" DataValueField="UserID" />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="CompletionDate" HeaderText="Completed"
DataFormatString="{0:MM-dd-yy}"></asp:BoundColumn>
<asp:BoundColumn DataField="LogItemNote"
HeaderText="Note"></asp:BoundColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete"
CommandName="Delete"></asp:ButtonColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="Black"
BackColor="#999999"></PagerStyle>
</asp:datagrid>

Nov 19 '05 #2

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

Similar topics

0
by: NETDeveloper | last post by:
Hi, I almost have my nested datagrid working properly. I created a datagrid on a user control and dropped that onto another datagrid. At first, I noticed when I was stepping through the code,...
0
by: Brett Hargreaves | last post by:
I'm having major problems with Datagrid and the update command. Basically when I enter into edit mode in my data grid then set a new value, the update command is not picking up the new value. ...
13
by: abdoly | last post by:
i wrote a code to update datagrid with the datagrid updatecommand but i cant get the updated values after being update that is the code private void DataGrid1_UpdateCommand(object source,...
1
by: siaj | last post by:
Helo All, If some one has faced a similar issue.. My datagrid Update command is not getting fired in fact it seems that the no event fires on clicking the update link. Although the cancel and the...
4
by: siaj | last post by:
Hello All, If some one has faced a similar issue.. My datagrid Update command is not getting fired in fact it seems that the no event fires on clicking the update link. Although the cancel and the...
9
by: Geraldine Hobley | last post by:
Hello I'm getting the above mentioned error in my applicatio I have a datagrid bound to a datasource like s MyDatagrid.DataSource = Mydataset.Tables(Order) - this all works fine However I...
4
by: William LaMartin | last post by:
In the past, I have filled a datagrid with data from an Access database table using a data adapter and dataset, where I used the OleDbCommandBuilder to have the program create the insert, delete...
0
by: logdenav | last post by:
I have a datagrid with a datatable for the datasource A thread update the datatable (acceptchanges) in the ui thread (Invoke or BeginInvoke) the datagrid makes changes but with a lot of data it's...
3
by: thebison | last post by:
Hi all, I hope someone can help with this relatively simple problem. I am building a timesheet application using ASP.NET C# with Visual Studio 2003.As it is only a protoype application, my...
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
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?
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
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...

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.