I ran into an error "object data not set refererece " ( most dreaded error message) at the point where the control parameter was assigned to the sqldatasource in the aspx page.
<asp:SqlDataSource ID="SqlDataSourceAppliedDateScreenDateCheck" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString1%>"
SelectCommand="PROC1"
SelectCommandType="StoredProcedure" DataSourceMode="DataReader"><SelectParameters><asp:ControlParameter ControlID="DropDownListCode" Name="NewCode"
PropertyName="SelectedValue" Type="Int32" /></SelectParameters></asp:SqlDataSource>
The DropdowListCode was not accessible because it is inside a FormView.I changed the above as follows to make it work.
Page1.aspx <asp:SqlDataSource ID="SqlDataSourceAppliedDateScreenDateCheck" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString1%>"
SelectCommand="PROC1"
SelectCommandType="StoredProcedure" DataSourceMode="DataReader">
</asp:SqlDataSource>
// removed the control parameter to add in the code behind page
Page1.aspx.vb
Protected Sub SqlDataSourceAppliedDateScreenDateCheck_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles SqlDataSourceAppliedDateScreenDateCheck.Selecting
'Pass the control parameter in the code behind
Dim drpNewCode As DropDownList = DirectCast(FormView1.FindControl("DropDownListCode"), DropDownList)
Dim sqlCtrlParam As SqlParameter = New SqlParameter("@NewCode", drpNewCode.SelectedValue.ToString())
e.Command.Parameters.Add(sqlCtrlParam)
End Sub
This blog is created to add all the information and experiences that I have learnt while working on MS sql server as a DBA. The blog is also updated frequently with the real world problem that I encounter hands on at work and the resolutions to resolve them. I hope this blog will be of some use to you and you will revisit. Thank you for stopping by and you are welcome to leave comments.
Showing posts with label asp.net. Show all posts
Showing posts with label asp.net. Show all posts
Thursday, October 18, 2012
Monday, August 20, 2012
BC30554: masterpage is ambiguous
I did not get this error on my dev machine. I did not get this compilation error in the staging site. I got this error in the produciton site.
Resolution: There was another file called masterpage2.aspx that was using the same namespace masterpage. It looked like a test file or for some reason a blank masterpage file was renamed this. Removed the masterpage2.aspx file , did a build and it worked fine.
Resolution: There was another file called masterpage2.aspx that was using the same namespace masterpage. It looked like a test file or for some reason a blank masterpage file was renamed this. Removed the masterpage2.aspx file , did a build and it worked fine.
Wednesday, July 18, 2012
Accessing control in a listview from code behind
In this case we are accessing the hyperlink control from the code behind to format the NavigateURL property of the control
Protected Sub lvTACRlist_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles lvTACRlist.ItemDataBound
Dim h1 As HyperLink = CType(e.Item.FindControl("hyperLink1"), HyperLink)
h1.NavigateUrl = h1.NavigateUrl + "&H=" + ddhoslist.SelectedValue.ToString()
End Sub
Protected Sub lvTACRlist_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles lvTACRlist.ItemDataBound
Dim h1 As HyperLink = CType(e.Item.FindControl("hyperLink1"), HyperLink)
h1.NavigateUrl = h1.NavigateUrl + "&H=" + ddhoslist.SelectedValue.ToString()
End Sub
Labels:
accessing control,
asp.net,
code behind,
controls,
listview
Accessing control in a gridview from code behind
Protected Sub GridView1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.PreRender
For Each gvRow In GridView1.Rows
If gvRow.RowType = DataControlRowType.DataRow Then
Dim h1 As HyperLink = CType(gvRow.Cells(0).Controls(0), HyperLink)
h1.NavigateUrl = h1.NavigateUrl & "&H=" & Request.QueryString("H")
End If
Next
End Sub
For Each gvRow In GridView1.Rows
If gvRow.RowType = DataControlRowType.DataRow Then
Dim h1 As HyperLink = CType(gvRow.Cells(0).Controls(0), HyperLink)
h1.NavigateUrl = h1.NavigateUrl & "&H=" & Request.QueryString("H")
End If
Next
End Sub
Monday, July 16, 2012
Accessing masterpage objects from child page
I had a project where I had to pass in the hospital code to the link button that was at the top of the each page . The top section of the each page was a masterpage.
I added a property called SetHospitalCode on the masterpage as follows
Public m_HosCode As String
Public Property SetHospitalCode() As String
Get
Return m_HosCode
End Get
Set(ByVal value As String)
m_HosCode = value
End Set
End Property
--------
Protected Sub DashBoard_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DashBoard.Click
If m_HosCode Is Nothing Then
Response.Redirect("DashBoard.aspx")
Else
Response.Redirect("DashBoard.aspx?H=" + m_HosCode.ToString())
End If
End Sub
I set the property from the each child page as follows
Dim getMaster As MasterPage
getMaster.SetHospitalCode = hospitalcode
where hospitalcode is the new value of the hospital from each page.
DashBoard is the ID of the linkbutton
I added a property called SetHospitalCode on the masterpage as follows
Public m_HosCode As String
Public Property SetHospitalCode() As String
Get
Return m_HosCode
End Get
Set(ByVal value As String)
m_HosCode = value
End Set
End Property
--------
Protected Sub DashBoard_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DashBoard.Click
If m_HosCode Is Nothing Then
Response.Redirect("DashBoard.aspx")
Else
Response.Redirect("DashBoard.aspx?H=" + m_HosCode.ToString())
End If
End Sub
I set the property from the each child page as follows
Dim getMaster As MasterPage
getMaster.SetHospitalCode = hospitalcode
where hospitalcode is the new value of the hospital from each page.
DashBoard is the ID of the linkbutton
Subscribe to:
Posts (Atom)