Congratulations to AcaCandy on her 100,000th post!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen blue screen boot bsod computer connection crash css dell driver drivers email error ethernet excel firefox firefox 3 freeze game hard drive internet internet explorer itunes laptop linux malware monitor network networking nvidia outlook outlook 2003 outlook 2007 outlook express partition password problem router slow software sound trojan usb video virus vista windows windows xp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
ASP.Net Newbie... Diaplaying Data in Dataset control


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
Jimmy444's Avatar
Computer Specs
Senior Member with 108 posts.
 
Join Date: Sep 2006
Experience: Intermediate
29-Feb-2008, 11:38 AM #1
ASP.Net Newbie... Diaplaying Data in Dataset control
Hi!
i'm a ASP.net newbie ( rather web development newbie).
By reading books i've got knowledge enough to populate a dataset with data and using it as source of data for a data grid view but

i want to access that dataset and display the data in that dataset in my some.aspx by my own (asp.net data binding controls don't fit the need). Like i'm trying to show an "area" (div with a particular background color to distinguish it from rest of page) on in the some.aspx that contains the data from a row of table present in dataset and some additional hard coded text... and i want to show those "areas" as many as the rows in the table in dataset ( a box for each row in table in dataset)

i guess i'm clear

thanks for answering, in advance
Fyzbo's Avatar
Senior Member with 1,777 posts.
 
Join Date: Feb 2002
Location: North Carolina, USA
Experience: Programming-Advanced|EVER
29-Feb-2008, 04:59 PM #2
I'm not exactly clear on the question. Perhaps you can provide the tables/columns in the dataset and how you would like them to be presented as html?

So far I've noticed that the data binding controls fit most scenarios. I have created a custom nested repeater control for data with a parent child relationship. I would suggest doing some reading on the repeater control as I find it to be very useful when displaying data.
Jimmy444's Avatar
Computer Specs
Senior Member with 108 posts.
 
Join Date: Sep 2006
Experience: Intermediate
29-Feb-2008, 05:12 PM #3
Hmm... i'll post here after studying repeater control.
Thanks a Lot

Last edited by Jimmy444 : 29-Feb-2008 05:13 PM. Reason: Miss spelled
Jimmy444's Avatar
Computer Specs
Senior Member with 108 posts.
 
Join Date: Sep 2006
Experience: Intermediate
01-Mar-2008, 03:31 AM #4
Ok Sir Fyzbo! i've explored Repeater control and its really a nice control. But i'm having a problem with it.

I've
Quote:
<asp:repeater runat="server" id="someId" etc >
<ItemTemplate>
<asp:Label runat="server" id="label1" visible="false" text="Request Accepted" />
<asp:LinkButton ID="acceptLinkButton" runat="server" CommandName="requestTaskLinkButton1">
<asp:Image ID="accpetImage" runat="server" ImageUrl="/App_Data/okTick.gif" />Accept</asp:LinkButton>
<asp:LinkButton ID="declineLinkButton" runat="server" CommandName="requestTaskLinkButton2">
<asp:Image ID="rejectImage" runat="server" ImageUrl="/App_Data/noCross.gif" />Decline</asp:LinkButton>
</ItemTemplate>
</asp:repeater>
So in the event handler for one of the LinkButton i want to access "label1".

I've tried

Quote:
protected void buttonLink_ItemCommand(object sender, RepeaterCommandEventArgs e)
{
if (e.CommandName=="requestTaskLinkButton1") //requesTaskLinkButton is <asp:LinkButton>
{

Control senderControl = (Control)sender;
Control requiredControl = senderControl.NamingContainer.FindControl("label1");
if (requiredControl != null)
{
requiredControl.Visible = true;
}

//Response.Write("Request Accepted"); //just for tracking
}

if (e.CommandName == "requestTaskLinkButton2")
{
Response.Write("Request Rejected"); //just for tracking
}
}
But the "requiredControl" is always "null". I want to make the "label1" visible (that invisible before this event handler runs) against the click of LinkButton ...
Please suggest a solution

Last edited by Jimmy444 : 01-Mar-2008 10:29 AM.
Fyzbo's Avatar
Senior Member with 1,777 posts.
 
Join Date: Feb 2002
Location: North Carolina, USA
Experience: Programming-Advanced|EVER
03-Mar-2008, 08:40 AM #5
I'm a little bit confused as to the desired result. Is it possible to show how the data is structured and the final html output you are trying to create?
Jimmy444's Avatar
Computer Specs
Senior Member with 108 posts.
 
Join Date: Sep 2006
Experience: Intermediate
03-Mar-2008, 02:32 PM #6
Sir as i stated in my previous post, asp:Repeater did the job i wanted. I mean displaying rows of table in a DataSet in xyz.aspx without binding any control to it.

Now i've found the solution of the problem i stated in my last post. Writing

Quote:
if (e.CommandName=="requestTaskLinkButton1") //requesTaskLinkButton is <asp:LinkButton>
{
HTMLGenericControl= e.Items.FindControl("Label1");
...
...
instead of
Quote:

if (e.CommandName=="requestTaskLinkButton1") //requesTaskLinkButton is <asp:LinkButton>
{
Control senderControl = (Control)sender;
Control requiredControl = senderControl.NamingContainer.FindControl("label1");
...
...
worked
Thanks a lot for your post. I'll post in this thread as i explore <asp:Repeater>

regards
Fyzbo's Avatar
Senior Member with 1,777 posts.
 
Join Date: Feb 2002
Location: North Carolina, USA
Experience: Programming-Advanced|EVER
03-Mar-2008, 03:20 PM #7
Just saw the naming convention "requiredControl" and was curious if you were doing validation, but did not want to assume. If you are doing validation you may want to look into the asp.net validation controls. If not, I'm glad you found a solution. Good luck with your website.
Jimmy444's Avatar
Computer Specs
Senior Member with 108 posts.
 
Join Date: Sep 2006
Experience: Intermediate
04-Mar-2008, 02:11 PM #8
Actually "requiredControl" meant that i required to access that control in item template
Yeah! i found a solution...

Thanks for the post
Jimmy444's Avatar
Computer Specs
Senior Member with 108 posts.
 
Join Date: Sep 2006
Experience: Intermediate
05-Mar-2008, 10:37 AM #9
Quote:
Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
I've a button say "replyButton" in <itemTemplate> in Repeater control.
This error is displayed in browser when event handler of "replyButton" is executed. I mean whenever i click "replyButton".
Please tell a solution.
Jimmy444's Avatar
Computer Specs
Senior Member with 108 posts.
 
Join Date: Sep 2006
Experience: Intermediate
05-Mar-2008, 10:40 AM #10
and here is the event handler of "replyButton"

Quote:
if (e.CommandName == "replyButton")
{
Session.Add("fromReplyEvent", "Reply Button pressed");
}
where "e" is "RepeaterCommandEventArgs" object passed as argument to event handler.
Jimmy444's Avatar
Computer Specs
Senior Member with 108 posts.
 
Join Date: Sep 2006
Experience: Intermediate
06-Mar-2008, 08:27 AM #11
ok i found out the solution. and the problem was that i had written the
Quote:
page.DataBind();
Quote:
if(!page.isPostBack){

}
Block.
Jimmy444's Avatar
Computer Specs
Senior Member with 108 posts.
 
Join Date: Sep 2006
Experience: Intermediate
06-Mar-2008, 08:32 AM #12
The problem has been solved but i'm encountering a new problem.
Now when i click the "replyButton" in repeater control, it leads us to the same page (as desired) instead of error, but it doesn't "refresh" the repeater's contents. I guess it just saves the contents of repeater control in "viewstate" when page is posted back and puts those values back in when page is refreshed on client side.
When i set "enableViewState" attribute of Repeater control to "false", on postback the repeater just disappeared from the page (may be because it didn't save anything in "viewstate", i guess).

Please propose a solution.
Fyzbo's Avatar
Senior Member with 1,777 posts.
 
Join Date: Feb 2002
Location: North Carolina, USA
Experience: Programming-Advanced|EVER
06-Mar-2008, 09:00 AM #13
It may be just a matter of calling repeaterID.DataBind(); after changing the data. Hard to say without having the source code available.
Jimmy444's Avatar
Computer Specs
Senior Member with 108 posts.
 
Join Date: Sep 2006
Experience: Intermediate
06-Mar-2008, 09:10 AM #14
The controls save their state in viewstate while page is posted back, but i want the Repeater to fetch its contents from DB every time page is refreshed (where post back or for first time) but the Repeater picks its contents from DB just first time (not when page is posted back).
One thing that i must make clear there is that i've written repeater's data binding code in page_load() event, i mean i didn't bind it to a data source visually. Code is here

Quote:
protected void Page_Load(object sender, EventArgs e)
{
String connStr = ConfigurationManager.ConnectionStrings["communityDBConnectionString"].ConnectionString;
String repeaterQuery = "SELECT id,fromUser,text FROM [MESSAGES] WHERE toUser='abc'";
//just hard-coded the user "abc" for simplicity purpose

SqlConnection conn = new SqlConnection(connStr);
SqlDataAdapter da = new SqlDataAdapter(repeaterQuery, conn);
DataTable dt = new DataTable();
da.Fill(dt);
Repeater1.DataSource = dt;
if (!Page.IsPostBack)
{
Repeater1.DataBind();
}
}
I want repeater to pick data from database every time the page is loaded...

Last edited by Jimmy444 : 06-Mar-2008 09:45 AM.
Fyzbo's Avatar
Senior Member with 1,777 posts.
 
Join Date: Feb 2002
Location: North Carolina, USA
Experience: Programming-Advanced|EVER
06-Mar-2008, 10:35 AM #15
You are fetching the data on every page load, but you are only binding the data when it is not a post back (if(!Page.IsPostBack). Repeater1.DataBind() is where the data will be loaded into the repeater. You can remove the if(!Page.IsPostBack) and it will bind on every page load, but this may cause more problems.

If you bind the data in the page_load and and event has been called from data that has changed it may cause problems. Also if the event changes the data it will not refresh the repeater so the data will still look wrong.

My advice would be to make a new method that contains the code to set the datasource and databind the repeater control. Then call this method in Page_Load inside of if(!Page.IsPostBack){} and also at the end of any event which will change the data. This will ensure that the data sent to the browser reflects what is in the database.
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 01:10 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.