DataGrid - Weird Update Command Problem

  • Thread starter Thread starter BW
  • Start date Start date
B

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>
 
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
 
Back
Top