IT Community - Software Programming, Web Development and Technical Support

ASP.NET Data Controls

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'...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > ASP and ASP.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  #21 (permalink)  
Old 08-03-2007, 05:20 AM
garunprasad garunprasad is offline
D-Web Trainee
 
Join Date: Mar 2007
Location: Chennai
Posts: 45
garunprasad is on a distinguished road
Send a message via ICQ to garunprasad Send a message via AIM to garunprasad Send a message via MSN to garunprasad Send a message via Yahoo to garunprasad Send a message via Skype™ to garunprasad
Default Re: Implementation Data Controls in asp.net

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #22 (permalink)  
Old 08-03-2007, 05:22 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Default Re: Implementation Data Controls in asp.net

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?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #23 (permalink)  
Old 08-03-2007, 05:23 AM
garunprasad garunprasad is offline
D-Web Trainee
 
Join Date: Mar 2007
Location: Chennai
Posts: 45
garunprasad is on a distinguished road
Send a message via ICQ to garunprasad Send a message via AIM to garunprasad Send a message via MSN to garunprasad Send a message via Yahoo to garunprasad Send a message via Skype™ to garunprasad
Thumbs up Re: Implementation Data Controls in asp.net

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #24 (permalink)  
Old 08-03-2007, 08:39 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Re: Implementation Data Controls in asp.net

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.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #25 (permalink)  
Old 08-04-2007, 01:22 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: Implementation Data Controls in asp.net

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.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #26 (permalink)  
Old 08-04-2007, 01:32 AM
H2o H2o is offline
D-Web Analyst
 
Join Date: Jul 2007
Posts: 246
H2o is on a distinguished road
Thumbs up Re: Implementation Data Controls in asp.net

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>&nbsp;&nbsp;<asp:label ID="lblCurrentPage" runat="server">
</asp:label></td>
</tr>
<tr >
<td>&nbsp;&nbsp;
<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>&nbsp;&nbsp; <%# DataBinder.Eval(Container.DataItem, "Product") %> </td>
</tr>
<tr >
<td>&nbsp;&nbsp; </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..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #27 (permalink)  
Old 08-08-2007, 05:08 AM
H2o H2o is offline
D-Web Analyst
 
Join Date: Jul 2007
Posts: 246
H2o is on a distinguished road
Question Re: Implementation Data Controls in asp.net

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..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #28 (permalink)  
Old 08-08-2007, 05:20 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: Implementation Data Controls in asp.net

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(" &nbsp;&nbsp;&nbsp;" & dr("FileName").ToString & " &nbsp;&nbsp;&nbsp;")
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 & " &nbsp;&nbsp;&nbsp;")
' 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.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #29 (permalink)  
Old 08-08-2007, 05:41 AM
H2o H2o is offline
D-Web Analyst
 
Join Date: Jul 2007
Posts: 246
H2o is on a distinguished road
Question Re: Implementation Data Controls in asp.net

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..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #30 (permalink)  
Old 08-08-2007, 05:42 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: Implementation Data Controls in asp.net

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.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #31 (permalink)  
Old 08-08-2007, 05:50 AM
H2o H2o is offline
D-Web Analyst
 
Join Date: Jul 2007
Posts: 246
H2o is on a distinguished road
Default Re: Implementation Data Controls in asp.net

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..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #32 (permalink)  
Old 08-08-2007, 05:54 AM
H2o H2o is offline
D-Web Analyst
 
Join Date: Jul 2007
Posts: 246
H2o is on a distinguished road
Thumbs up Re: Implementation Data Controls in asp.net

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..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #33 (permalink)  
Old 08-08-2007, 05:56 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: Implementation Data Controls in asp.net

hi,

about the solution, have you set AllowPaging='true'?
<asp:GridView PageSize="1" AllowPaging="true" DataSourceID="SqlDataSource1" ID="GridView1" runat="server">
</asp:GridView>



Regards
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #34 (permalink)  
Old 08-08-2007, 05:57 AM
H2o H2o is offline
D-Web Analyst
 
Join Date: Jul 2007
Posts: 246
H2o is on a distinguished road
Thumbs up Re: Implementation Data Controls in asp.net

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..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #35 (permalink)  
Old 08-08-2007, 05:59 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: Implementation Data Controls in asp.net

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #36 (permalink)  
Old 08-08-2007, 06:28 AM
H2o H2o is offline
D-Web Analyst
 
Join Date: Jul 2007
Posts: 246
H2o is on a distinguished road
Default Re: Implementation Data Controls in asp.net

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..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #37 (permalink)  
Old 08-08-2007, 06:42 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: Implementation Data Controls in asp.net

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #38 (permalink)  
Old 08-08-2007, 06:44 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: Implementation Data Controls in asp.net

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>
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #39 (permalink)  
Old 08-08-2007, 06:47 AM
H2o H2o is offline
D-Web Analyst
 
Join Date: Jul 2007
Posts: 246
H2o is on a distinguished road
Thumbs up Re: Implementation Data Controls in asp.net

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..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #40 (permalink)  
Old 08-16-2007, 05:32 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Question Re: Implement Data Controls in asp.net

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On