
lorena
Avatar/Signature-
Posts
134 -
Joined
-
Last visited
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by lorena
-
All I want to do is put data into a grid. Here is my code: Sub BindData() Dim strConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\\intranet\databases\open_en.mdb" Dim objConn As New OleDb.OleDbConnection(strConnString) Dim strSQL As String = "SELECT * FROM InsChange" Dim objCommand As New OleDb.OleDbCommand(strSQL, objConn) Dim objDA As New OleDb.OleDbDataAdapter objDA.SelectCommand = objCommand Dim objDS As New DataSet objDA.Fill(objDS) objConn.Close() grdRecs.DataSource = objDS grdRecs.DataBind() End Sub I keep getting "Object reference not set to an instance of an object" Any help would be appreciated.
-
Thanks again for your help
-
Yes, I am still chugging along with VS2003. The BoundColumn code - is that still in the PreRender event?
-
Thanks so much. I will give that a shot!
-
I have a datagrid that allows editing. If a certain group of users accesses the page, however, I would like the page set up to only edit one field and not all of the edit fields? The admin user would have the ability to edit all fields in the grid. Can this be done through ItemDataBound? If so, does anyone have an example of how to do it? Hope this makes sense.
-
SOLVED!Found the solution in Scott Mitchell's "ASP.NET Data Controls". Here is what worked: If e.Item.ItemType <> ListItemType.Header And _ e.Item.ItemType <> ListItemType.Footer Then Dim hl As HyperLink = e.Item.Cells(0).Controls(0) Dim navURL As String hl.Text = "View Details" Select Case intCat Case 10, 20 navURL = "mgrid_details.aspx?cat=0&id=" & _ Server.UrlEncode(DataBinder.Eval(e.Item.DataItem, "req_id")) Case 35, 45, 55 navURL = "mgrid_details.aspx?cat=5&id=" & _ Server.UrlEncode(DataBinder.Eval(e.Item.DataItem, "req_id")) End Select hl.Target = "_blank" hl.NavigateUrl = navURL So, if anyone else encounters this problem, I hope this helps
-
I have a form with a datagrid and I would like to be able to change a portion of the DataNavigateUrlFormatString depending on other factors in the web app. Here is my code: <asp:HyperLinkColumn HeaderText="Details" Text="View Details" DataNavigateUrlField="Req_ID" Target="_blank" DataNavigateUrlFormatString="mgrid_details.aspx?id={0}&cat=0" /> Specifically, I want to change "cat=0" to "cat=5" depending on whether the record will be editable or not. Is there a way to do this?
-
I have an aspx page that is supposed to link to an "index.aspx" page in each of several folders. I have been able to figure out how to list the names in a datalist but I would like to list them as hyperlinks in a datagrid (/foldername/index.aspx) Here is the code for the datalist: Dim Directories As New IO.DirectoryInfo(Server.MapPath("")) Dim Directory As IO.DirectoryInfo For Each Directory In Directories.GetDirectories ListBox1.Items.Add(Directory.Name) Next If I could get some tips for the code, I would really appreciate it. I know how to hyperlink to files, I am just having problems with linking to the file within a folder. THanks
-
Never mind - page works fine. One of the folks entering the files into the directory was putting periods in the filenames.
-
I have several pages that are supposed to list all the files that are .pdf files in a certain directory. For some reason, the page displays one less file than is actually in the directory. What am I doing wrong? Here is my code: Sub BindGrid() Dim dirInfo As New System.IO.DirectoryInfo(Server.MapPath("/p1/Docs/JobOrders/6500 - 6599")) Dim arrFileInfo As Array Dim filesInfo As System.IO.FileInfo Dim filesTable As New DataTable() Dim drFiles As DataRow Dim dvFiles As DataView Dim ofn, ext As String Dim charCt, fileCt As Integer filesTable.Columns.Add("Name", Type.GetType("System.String")) filesTable.Columns.Add("LastWriteTime", Type.GetType("System.DateTime")) arrFileInfo = dirInfo.GetFiles("*.pdf") fileCt = 0 For Each filesInfo In arrFileInfo drFiles = filesTable.NewRow() ofn = filesInfo.Name ext = Right(ofn, 4) charCt = InStr(ofn, ".") - 1 ofn = Mid(ofn, 1, charCt) drFiles("Name") = ofn drFiles("LastWriteTime") = filesInfo.LastWriteTime filesTable.Rows.Add(drFiles) fileCt += 1 Next filesInfo dvFiles = filesTable.DefaultView If SortAscending then dvFiles.Sort = SortExpression & " ASC" Else dvFiles.Sort = SortExpression & " DESC" End If dgFiles.DataSource = dvFiles dgFiles.DataBind() If fileCt < 51 Then GridPagerVisibility(False) Else GridPagerVisibility(True) End If lblyourmom.text = fileCt End Sub
-
I am having problems because I need to create a series of .aspx pages (VS 2003) which all have the same basic function. They will list files into a pageable sortable datagrid. I have this working code (I am shortening some of it): Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) If Not Page.IsPostBack Then SortExpression = "Name" SortAscending = True BindGrid() End If End Sub Sub BindGrid() ' deleted code that reads the files and writes to the grid If SortAscending then dvFiles.Sort = SortExpression & " ASC" Else dvFiles.Sort = SortExpression & " DESC" End If dgFiles.DataSource = dvFiles dgFiles.DataBind() If fileCt < 51 Then GridPagerVisibility(False) Else GridPagerVisibility(True) End If End Sub Private Sub GridPagerVisibility(ByVal ShowHide As Boolean) dgFiles.PagerStyle.Visible = ShowHide End Sub Private Property SortExpression() As String Get Dim o As Object = ViewState("SortExpression") If o Is Nothing Then Return String.Empty Else Return o.ToString End If End Get Set(ByVal Value As String) ViewState("SortExpression") = Value End Set End Property Private Property SortAscending() As Boolean Get Dim o As Object = ViewState("SortAscending") If o Is Nothing Then Return True Else Return Convert.ToBoolean(o) End If End Get Set(ByVal Value As Boolean) ViewState("SortAscending") = Value End Set End Property Sub dgFiles_SortCommand(ByVal sender As Object, ByVal e As DataGridSortCommandEventArgs) If e.SortExpression = Me.SortExpression Then SortAscending = Not SortAscending Else SortAscending = True End If Me.SortExpression = e.SortExpression 'label1.text = SortExpression & "," & SortAscending.ToString BindGrid() End Sub Sub dgFiles_Paging(ByVal s As Object, ByVal e As DataGridPageChangedEventArgs) dgFiles.CurrentPageIndex = e.NewPageIndex BindGrid() End Sub All of the pages (and there will be many many of them) will have this code. Is there any other way to re-use it other than cutting and pasting from one .aspx page to the next? Needless to say, I have not done much with re-using code to date Thanks for any help
-
ASP.Net - search sub folders in directory
lorena replied to lorena's topic in Directory / File IO / Registry
Thanks. That does help me to kind of see what I need to do -
ASP.Net - search sub folders in directory
lorena replied to lorena's topic in Directory / File IO / Registry
So I am a little dense here but what would a recursive search look like? I know what it looks like in asp but I am stumped as to how to convert it to .aspx -
I am trying to create a class that can be invoked to create a bi-directional sort of any datagrid on the pages of the site I am working on. This is only the second time I have ever tried this and I am getting errors in the code but I am not sure why. I want to incorporate ViewState as part of the class. This is my code: Imports System.Web.UI.Page Public Class clsSort Private Property SortExpression() As String Get Dim o As Object = ViewState("SortExpression") If o Is Nothing Then Return String.Empty Else Return o.ToString End If End Get Set(ByVal Value As String) ViewState("SortExpression") = Value End Set End Property Private Property SortAscending() As Boolean Get Dim o As Object = ViewState("SortAscending") If o Is Nothing Then Return True Else Return Convert.ToBoolean(o) End If End Get Set(ByVal Value As Boolean) ViewState("SortAscending") = Value End Set End Property End Class I included the System.Web in my Project references This is my error message: 'System.Web.UI.Control.Protected Overridable Overloads ReadOnly Property ViewState() As System.Web.UI.StateBag' is not accessible in this context because it is 'Protected' It seems like there should be a way to do this so I don't have to keep copying the code each time. I just can't quite figure it out.
-
ASP.Net - search sub folders in directory
lorena replied to lorena's topic in Directory / File IO / Registry
More Information sorry - the code I posted only searches the root folder and none of the subfolders. -
I am trying to create a search page in VS 2003 that will search all of the subfolders in a directory. I had a way to do it in asp but .NET is different. I tried this: Dim strPath As String = "/intranet/Quality/Discrepancy Reports Closed" Dim strQuery As String Dim myDirInfo As DirectoryInfo strQuery = txtQuery.Text If strQuery = "" Then strQuery = CStr(Request.QueryString("query")) txtQuery.Text = strQuery myDirInfo = New DirectoryInfo(Server.MapPath(strPath)) dgFiles.DataSource = myDirInfo.GetFiles("*" & strQuery & "*") dgFiles.DataBind() Any suggestions would be appreciated.
-
Okay - No longer confused I forgot to add a reference to the class in my code behind. It all makes sense now - and it works :D
-
I have several functions common to almost all of the pages in my web application. According to what I have read (and this is the first time I have tried to do this), I should be able to create a class that contains the function(s) and access it from within my code (either code-behind or .aspx) Here is the class code: Public Class mreqFunctions Public Shared Function showShortDate(ByVal aDate As Object) If Not IsDBNull(aDate) Then Return aDate.ToShortDateString End If End Function End Class and I am using it to display dates in the ItemTemplate of a datagrid. I tried two different ways: <ItemTemplate> <asp:Label ID="lblReqCompDate" Runat="server" text='<%=mreqFunctions.showShortDate(DataBinder.Eval(Container.DataItem,"requested_comp_date")) %>' /> </ItemTemplate> (just displays blank field - no error but no date either) And this way: <ItemTemplate> <asp:Label ID="lblReqCompDate" Runat="server" text='<%#mreqFunctions.showShortDate(DataBinder.Eval(Container.DataItem,"requested_comp_date")) %>' /> </ItemTemplate> Which gives me this error:BC30451: Name 'mreqFunctions' is not declared What do I need to do to declare the function? I am using VS 2003. I am really confused and would appreciate any help
-
I just wanted to follow up. I put this in my code and it worked perfectly. Thanks so much!
-
Where do I actually put the code? Do I create a separate Class Module or put it in the Global.asax file? Would this be the correct code? Public Class ShortDateClass Public Shared Function showShortDate(ByVal aDate As Object) If Not IsDBNull(aDate) Then Return aDate.ToShortDateString End If End Function End Class
-
I have a little function that just checks to see whether a database field is a date or null and I wanted to be able to make it accessible from all the forms on the site it is attached to - so I did this: Public Class ShortDateClass Public Function showShortDate(ByVal aDate As Object) If Not IsDBNull(aDate) Then Return aDate.ToShortDateString End If End Function End Class My question is this: how do I access this function from within a datagrid, for example? This is the code I used but it doesn't work: <asp:TemplateColumn HeaderText="Sched Complete Date"> <ItemTemplate> <asp:Label ID="lblSchedCompDate" Runat="server" text='<%#ShortDateClass.showShortDate(DataBinder.Eval(Container.DataItem,"sched_comp_date"))%>'/> </ItemTemplate> </asp:TemplateColumn> help?
-
Thanks. I will try that out.
-
I have a series of pages that display closed files in different folders. Some of the folders have many files and some have few. Is it possible to create an event that displays or hides the Pager based on the file count? Thanks in advance
-
thanks very much. i will give that a shot.
-
I do development work by connecting through a network drive to our intranet server because VS.Net is not loaded on the machine. I have been trying to set up a data connection for a project using VS.Net Server Explorer. The problem is that the connection string VS.Net sets up references my network drive "I:\" which would be meaningless when users access the pages that would use the connection. Is there anyway to change this? To use the unc? I know I how to code a connect string and all that but I wanted to try using the data connection. Thanks