This is a discussion on ASP.NET Data Controls within the ASP and ASP.NET Programming forums, part of the Web Development category; Hi I am assigning the same ID to the check box which I am searching for using FindControl() method. I'...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi I am assigning the same ID to the check box which I am searching for using FindControl() method. I'm doing everything the same as mentioned here: WEBSWAPP Development Inc. except for creating the columns for the GridView in the Page_Load method. The columns for the GridView are being created just before data is bound to the GridView in a number of different places in the .aspx page
__________________ G.A.P |
| Sponsored Links |
| |||
| Hi You could trace out the ID of every control in gvr: foreach (Control ctrlChild in gvr.Controls) { Trace.Write("Child Item", ctrlControl.ID); } and see what .net thinks is there? |
| |||
| Hi guys, It seems the server is not aware of the control being there at all. I tried a different approach by adding a new cell with a check box control for each row in the RowCreated event, and it works beautifully. Thanks guys.
__________________ G.A.P |
| |||
| hey guys, I have implemented Repeater control in my web page. Working fine and information is displayed. The 30datas are displayed in this page. We dont have a paging properties in repeater control. Can anyone help me how to implement a paging to Repeater control?
__________________ The OXYGEN Delivers edgy, intelligent Technology to all... Last edited by oxygen : 08-03-2007 at 10:59 PM. |
| |||
| hi Oxy.... Try to implement it. I have given you the gest The PagedDataSource class encapsulates the properties of the Repeater control that allow it to perform paging. PagedDataSource pagedDataSource = new PagedDataSource(); DataView userGroupMemberDataView = new DataView(); userGroupMemberDataView = loadMyGroup(); pagedDataSource.DataSource = userGroupMemberDataView; pagedDataSource.AllowPaging = true; pagedDataSource.PageSize = 24; Last edited by Venkat : 08-04-2007 at 01:24 AM. |
| |||
| hi, Try this code Oxygen, its worked for me..., The PagedDataSource class encapsulates the properties of the DataGrid control that allow it to perform paging. But we can use the class with Repeater and DataList controls to perform paging in much the same way as a DataGrid. Body of the page <table width="100%" border="0"> <tr > <td> <asp:label ID="lblCurrentPage" runat="server"> </asp:label></td> </tr> <tr > <td> <asp:HyperLink id="lnkPrev" runat="server"><< Prev</asp:HyperLink> <asp:HyperLink id="lnkNext" runat="server">Next >></asp:HyperLink></td> </tr> </table><asp:repeater ID="Repeater1" runat="server"> <itemtemplate> <table width="100%" border="0"> <tr > <td> <%# DataBinder.Eval(Container.DataItem, "Product") %> </td> </tr> <tr > <td> </td> </tr> </table> </itemtemplate> </asp:repeater> <script language="C#" runat="server"> public void Page_Load(Object src,EventArgs e) { DataSet ds; //Instanciate Dataset PagedDataSource objPds = new PagedDataSource(); objPds.DataSource = ds.Tables[0].DefaultView; objPds.AllowPaging = true; objPds.PageSize = 5; int CurPage; if (Request.QueryString["Page"] != null) CurPage=Convert.ToInt32(Request.QueryString["Page"]); else CurPage=1; objPds.CurrentPageIndex = CurPage-1; lblCurrentPage.Text = "Page: " + CurPage.ToString(); if (!objPds.IsFirstPage) lnkPrev.NavigateUrl=Request.CurrentExecutionFilePa th + "?Page=" + Convert.ToString(CurPage-1); if (!objPds.IsLastPage) lnkNext.NavigateUrl=Request.CurrentExecutionFilePa th + "?Page=" + Convert.ToString(CurPage+1); Repeater1.DataSource=objPds; Repeater1.DataBind(); } < /script>
__________________ H2O Without us, no one can survive.. |
| |||
| I have a GridView, I want the user to download an attachment . If there is an attachment related to that specific record. I have to download it. Can anyone help me...
__________________ H2O Without us, no one can survive.. |
| |||
| Given below is some of my code: Private Sub projectGridView_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs) ' Use the RowType property to determine whether the ' row being created is the header row. If (e.Row.RowType = DataControlRowType.Header) Then For i As Integer = 0 To e.Row.Cells.Count - 1 ' Create the sorting image based on the sort direction. Dim sortImage As Image = New Image 'Test whether or not session is exist If Session(projectGridView.Columns(i).SortExpression) Is Nothing Or Session(projectGridView.Columns(i).SortExpression) = "ASC" Then sortImage.ImageUrl = "../images/arrow_up.gif" sortImage.AlternateText = "Ascending Order" Else sortImage.ImageUrl = "../images/arrow_down.gif" sortImage.AlternateText = "Descending Order" End If ' Add the image to the appropriate header cell. e.Row.Cells(i).Controls.Add(New LiteralControl(" ")) e.Row.Cells(i).Controls.Add(sortImage) Next End If If (e.Row.RowType = DataControlRowType.DataRow) Then Dim attachmentImage As Image = New Image attachmentImage.ImageUrl = "../images/paperclip.gif" attachmentImage.AlternateText = "Attachment" 'Dim fileName As String If projectGridView.Columns(0).HeaderText = "ID" Then Dim connString As String Dim con As SqlConnection Try connString = System.Web.Configuration.WebConfigurationManager.C onnectionStrings("ConnectionString1").ConnectionSt ring con = New SqlConnection(connString) Dim cmd As SqlCommand = New SqlCommand() cmd.Connection = con cmd.CommandText = "dbo.GetOpenProjectInfo" cmd.CommandType = CommandType.StoredProcedure Dim adapter As New SqlDataAdapter(cmd) Dim proj As New DataSet adapter.Fill(proj, "Projects") 'Response.Write(proj.Tables(0).Rows.Count & " ") 'Response.Write(proj.Tables(0).Columns.Count & " ") If Not [String].IsNullOrEmpty(e.Row.Cells(0).ToString) Then Dim i Dim fileURL As String Dim dr As DataRow dr = proj.Tables(0).Rows(e.Row.RowIndex) If [String].IsNullOrEmpty(dr.Item("FileName").ToString) = False Then fileURL = Server.MapPath(".") & "\upload\" & dr("FileName").ToString 'Response.Write(" " & dr("FileName").ToString & " ") e.Row.Cells(0).Controls.Add(New LiteralControl("<a href=""" & fileURL & """>")) e.Row.Cells(0).Controls.Add(attachmentImage) e.Row.Cells(0).Controls.Add(New LiteralControl("</a>")) End If End If 'For i = 0 To ((proj.Tables(0).Rows.Count) - 1) ' Response.Write("<br />" & i & "<br />") ' Response.Write(dr.Item("FileName").ToString) 'Next i 'For Each dr As DataRow In proj.Tables(0).Rows ' If [String].IsNullOrEmpty(dr("FileName").ToString) = False Then ' Response.Write(dr("FileName").ToString & " ") ' e.Row.Cells(0).Controls.Add(New LiteralControl("")) ' e.Row.Cells(0).Controls.Add(attachmentImage) ' End If 'Next dr Try con.Open() cmd.ExecuteNonQuery() Catch ex As Exception Response.Write(ex) Finally con.Close() con.Dispose() End Try Catch ex As ApplicationException Response.Write("Could not load the database") End Try End If End If End Sub Currently the items on RowIndex 1 and 2 have attachments. When the page loads, the attachments image shows up next the "ID" column in those rows. |
| |||
| hey, The problem now is with the paging and sorting events. If I change the page or if I sort the Grid View, the attachment image stays on rows 2 and 3 and doesn't move with it's related "ID" row. help out!
__________________ H2O Without us, no one can survive.. |
| |||
| Hi: When we want to pop up download box, we have to do something like this: protected void Page_Load(object sender, EventArgs e) { Response.AppendHeader("content-disposition", "attachment; filename=" + "1.bmp"); Response.ContentType = "Application/pdf"; //Get the physical path to the file. string FilePath = MapPath("images/1.bmp"); //Write the file directly to the HTTP content output stream. Response.WriteFile(FilePath); Response.End(); } Only thing is to pass query string to that page. You can sill use <a> then. If your problem isn't solved, please inform me. |
| |||
| hey, you've given fixed file info, however in my application, I don't find out the file name's until the GridView is loaded (or loading). How would I go about implementing this in that case? Would I have to make a call to the db before I call my GetData() method?
__________________ H2O Without us, no one can survive.. |
| |||
| hey, I tried the code you provided for the paging template and I get the following error: Specified argument was out of the range of valid values. Parameter name: index Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: index Source Error: Line 683: Dim tc As New TableCell() Line 684: tc.Controls.Add(l) Line 685: Me.projectGridView.Controls(0).Controls(Me.project GridView.Controls(0).Controls.Count - 1).Controls(0).Controls(0).Controls(0).Controls.Ad dAt(0, tc) Line 686: 'Previous and Next Line 687: Dim tp As New TableCell
__________________ H2O Without us, no one can survive.. |
| |||
| hi, about the solution, have you set AllowPaging='true'? <asp:GridView PageSize="1" AllowPaging="true" DataSourceID="SqlDataSource1" ID="GridView1" runat="server"> </asp:GridView> Regards |
| |||
| hi, I do have AllowPaging = True. <asp:GridView ID="projectGridView" runat="server" AutoGenerateColumns="False" DataKeyNames="ProjID" AllowPaging="True" OnRowCreated="projectGridView_RowCreated" GridLines="None" AllowSorting="true" OnSorting="projectGridView_Sorting" OnRowDataBound="projectGridView_RowDataBound" OnDataBound="projectGridView_DataBound" OnPageIndexChanging="projectGridView_PageIndexChan ging" PagerSettings-Position="TopAndBottom" PagerStyle-HorizontalAlign="Right" PagerSettings-Mode="Numeric">
__________________ H2O Without us, no one can survive.. |
| |||
| hi, <asp:GridView PageSize="1" AllowPaging="true" DataSourceID="SqlDataSource1" ID="GridView1" runat="server"> </asp:GridView> Please remove your PageTemplate and try again. My code just share some idea that can do the same thing without PageTemplate. Regards Venki |
| |||
| hi, Yeah problem is resolved .. The download problem isn't solved because I'm still not sure how I'm supposed to get all the file names and associate them with the correct ProjID in the PageLoad() method.
__________________ H2O Without us, no one can survive.. |
| |||
| hi, try this code Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) GetAttachmentInfo() If Not Page.IsPostBack Then GetData() End If End Sub Sub GetAttachmentInfo() Dim connString As String Dim con As SqlConnection Try connString = System.Web.Configuration.WebConfigurationManager.C onnectionStrings("ConnectionString1").ConnectionSt ring con = New SqlConnection(connString) Dim cmd As SqlCommand = New SqlCommand() cmd.Connection = con cmd.CommandText = "dbo.GetAttachmentInfo" cmd.CommandType = CommandType.StoredProcedure Dim adapter As New SqlDataAdapter(cmd) Dim attachments As New DataSet adapter.Fill(attachments, "Attachments") Dim i Dim fileURL As String For i = 0 To attachments.Tables(0).Rows.Count - 1 Dim dr As DataRow dr = attachments.Tables(0).Rows(i) Dim fileName = dr.Item("FileName").ToString If [String].IsNullOrEmpty(fileName) = False Then 'Get the physical path to the file. fileURL = Request.ApplicationPath.ToString & "/securesite/upload/" & fileName Response.AppendHeader("content-disposition", "attachment; filename=" + fileName) Response.ContentType = "Application/octet-stream" 'pdf" 'Write the file directly to the HTTP content output stream. Response.WriteFile(fileURL) Response.End() End If Next i Try con.Open() cmd.ExecuteNonQuery() Catch ex As Exception Response.Write(ex) Finally con.Close() con.Dispose() End Try Catch ex As ApplicationException Response.Write("Could not load the database") End Try End Sub try thi |
| |||
| hi, You can use link button to do this…, Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click Response.AppendHeader("content-disposition","attachment; filename=" & "1.bmp") Response.ContentType = "Application/pdf" 'Get the physical path to the file. Dim FilePath As String = MapPath("1.bmp") 'Write the file directly to the HTTP content output stream. Response.WriteFile(FilePath) Response.End() End Sub <asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton> |
| |||
| Hey guys, Thanks for the code. I managed to get it working. Now I get the download dialog box after the user clicks on the download icon.
__________________ H2O Without us, no one can survive.. |
| |||
| hey guys, can anyone give me the soultion.... There are 10 different Categories stored in PersonalityCategory table, each category has 10 different questions which will be stored in PersonalityQuestion table with PersonalityCategoryId has forign key, each PersonalityQuestion has 5 different options which will be stored in PersonalityOption table with PersoanlityQuestionId has a forign key. Here i want to form a page like a content page in a book with a help of these three tables. To display the information, what type of Data control is to be used?
__________________ Venkat knowledge is Power |