Advertisement
| 05.09.2008 at 11:52AM PDT, ID: 23390481 | Points: 500 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: |
<!--ASP CODE, Inside edititemtemplate of a FormView control. InsertItem uses AJAX to set the date, using same VB Method, which works fine-->
<asp:DropDownList ID="cboFinalResult" runat="server" SelectedValue='<%# Bind("finalResult") %>' AutoPostBack="True" OnSelectedIndexChanged="cboFinalResult_SelectedIndexChanged">
<asp:ListItem Value="">not entered</asp:ListItem>
<asp:ListItem Value="Contact">Destroyed</asp:ListItem>
<asp:ListItem Value="No Contact">Re-Exported</asp:ListItem>
<asp:ListItem Value="Sale">Treated</asp:ListItem>
</asp:DropDownList>
<br />
Final Result Date<asp:CompareValidator ID="cmpFinalResultDate" runat="server" ControlToValidate="txtFinalResultDate"Operator="DataTypeCheck" Type="date" ErrorMessage="*date" Font-Size=".8em"></asp:CompareValidator><br />
<asp:TextBox ID="txtFinalResultDate" runat="server" Text='<%# Bind("finalResultdate", "{0:d}") %>'></asp:TextBox>
'VB.NET CODE, WHICH THROWS THE EXCEPTION
Protected Sub cboFinalResult_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboFinalResult.SelectedIndexChanged
If CType(fvSales.FindControl("cboFinalResult"), DropDownList).Text <> "Not Entered" Then
Me.txtFinalResultDate.Text = Today.ToShortDateString 'THIS LINE CAUSES THE EXCEPTION*********************************
End If
End Sub
<!-- EXCEPTION INFORMATION-->
System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="App_Web_qy1swmje"
StackTrace:
at saleEntry.cboFinalResult_SelectedIndexChanged(Object sender, EventArgs e) in c:\inetpub\wwwroot\web\saleEntry.aspx.vb:line 390
at System.Web.UI.WebControls.ListControl.OnSelectedIndexChanged(EventArgs e)
at System.Web.UI.WebControls.DropDownList.RaisePostDataChangedEvent()
at System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent()
at System.Web.UI.Page.RaiseChangedEvents()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
|
| Microsoft |
| Apple |
| Internet |
| Gamers |
| Digital Living |
| Virus & Spyware |
| Hardware |
| Software |
| ITPro |
| Developer |
| Storage |
| OS |
| Database |
| Security |
| Programming |
| Web Development |
| Networking |
| Other |
| Community Support |
| 05.09.2008 at 12:02PM PDT, ID: 21535591 |
| 05.09.2008 at 12:22PM PDT, ID: 21535739 |
1: 2: 3: 4: |
Dim txtFinalResultDate As TextBox = DirectCAst(Formview1.Findcontrol("txtFinalResultDate"), TextBox)
txtFinalResultDate.Text = Today.ToShortDateString
|
| 05.09.2008 at 12:31PM PDT, ID: 21535789 |
| 05.09.2008 at 03:40PM PDT, ID: 21536832 |
| 05.12.2008 at 06:43AM PDT, ID: 21546893 |
1: 2: 3: 4: 5: |
If fvSales.CurrentMode = FormViewMode.Edit Then
Dim tb1 As TextBox = DirectCast(fvSales.FindControl("txtFinalResultDate"), TextBox)
tb1.Text = "Today.ToShortDateString
End I
|
| 05.12.2008 at 07:36AM PDT, ID: 21547342 |
| 05.12.2008 at 07:37AM PDT, ID: 21547356 |
| 05.12.2008 at 07:47AM PDT, ID: 21547438 |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: |
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test2.aspx.vb" MaintainScrollPositionOnPostback="true" Inherits="test2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:FormView ID="FormView1" runat="server" CellPadding="4" DataKeyNames="WorkoutPersonID"
DataSourceID="SqlDataSource1" ForeColor="#333333">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged1">
<asp:ListItem>- Select Item - </asp:ListItem>
<asp:ListItem Value="Changed">Change 1 made</asp:ListItem>
<asp:ListItem Value="Changed">Change 2 made</asp:ListItem>
</asp:DropDownList><br />
WorkoutPersonID:
<asp:Label ID="WorkoutPersonIDLabel1" runat="server" Text='<%# Eval("WorkoutPersonID") %>'></asp:Label><br />
WorkoutPerson:
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("WorkoutPerson") %>'></asp:TextBox><br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
Text="Update"></asp:LinkButton>
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<InsertItemTemplate>
WorkoutPerson:
<asp:TextBox ID="WorkoutPersonTextBox" runat="server" Text='<%# Bind("WorkoutPerson") %>'>
</asp:TextBox><br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</InsertItemTemplate>
<ItemTemplate>
WorkoutPersonID:
<asp:Label ID="WorkoutPersonIDLabel" runat="server" Text='<%# Eval("WorkoutPersonID") %>'></asp:Label><br />
WorkoutPerson:
<asp:Label ID="WorkoutPersonLabel" runat="server" Text='<%# Bind("WorkoutPerson") %>'></asp:Label><br />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
Text="Edit"></asp:LinkButton>
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
Text="Delete"></asp:LinkButton>
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
Text="New"></asp:LinkButton>
</ItemTemplate>
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DavesDesignConnectionString %>"
DeleteCommand="DELETE FROM [WorkoutPerson] WHERE [WorkoutPersonID] = @WorkoutPersonID"
InsertCommand="INSERT INTO [WorkoutPerson] ([WorkoutPerson]) VALUES (@WorkoutPerson)"
SelectCommand="SELECT [WorkoutPersonID], [WorkoutPerson] FROM [WorkoutPerson]"
UpdateCommand="UPDATE [WorkoutPerson] SET [WorkoutPerson] = @WorkoutPerson WHERE [WorkoutPersonID] = @WorkoutPersonID">
<DeleteParameters>
<asp:Parameter Name="WorkoutPersonID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="WorkoutPerson" Type="String" />
<asp:Parameter Name="WorkoutPersonID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="WorkoutPerson" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<br />
</form>
</body>
</html>
***************CODE BEHIND
Partial Class test2
Inherits System.Web.UI.Page
Protected Sub DropDownList1_SelectedIndexChanged1(ByVal sender As Object, ByVal e As System.EventArgs)
If FormView1.CurrentMode = FormViewMode.Edit Then
Dim ddl1 As DropDownList = DirectCast(FormView1.FindControl("DropDownList1"), DropDownList)
If ddl1.SelectedValue <> "- Select Item -" Then
Dim tb1 As TextBox = DirectCast(FormView1.FindControl("TextBox1"), TextBox)
tb1.Text = Today.ToShortDateString
End If
End If
End Sub
End Class
|