# ASP.Net Newbie... Diaplaying Data in Dataset control



## Jimmy444 (Sep 10, 2006)

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 (Feb 6, 2002)

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 (Sep 10, 2006)

Hmm... i'll post here after studying repeater control.
Thanks a Lot


----------



## Jimmy444 (Sep 10, 2006)

Ok Sir Fyzbo! i've explored Repeater control and its really a nice control. But i'm having a problem with it.

I've


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


So in the event handler for one of the LinkButton i want to access "label1".

I've tried



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


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


----------



## Fyzbo (Feb 6, 2002)

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 (Sep 10, 2006)

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



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


instead of 


> 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 (Feb 6, 2002)

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 (Sep 10, 2006)

Actually "requiredControl" meant that i required to access that control in item template 
Yeah! i found a solution...

Thanks for the post


----------



## Jimmy444 (Sep 10, 2006)

> 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 (Sep 10, 2006)

and here is the event handler of "replyButton"



> if (e.CommandName == "replyButton")
> {
> Session.Add("fromReplyEvent", "Reply Button pressed");
> }


where "e" is "RepeaterCommandEventArgs" object passed as argument to event handler.


----------



## Jimmy444 (Sep 10, 2006)

ok i found out the solution. and the problem was that i had written the 


> page.DataBind();





> if(!page.isPostBack){
> 
> }


Block.


----------



## Jimmy444 (Sep 10, 2006)

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 (Feb 6, 2002)

It may be just a matter of calling repeaterID.DataBind(); after changing the data. Hard to say without having the source code available.


----------



## Jimmy444 (Sep 10, 2006)

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



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


I want repeater to pick data from database every time the page is loaded...


----------



## Fyzbo (Feb 6, 2002)

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.


----------



## Jimmy444 (Sep 10, 2006)

> You can remove the if(!Page.IsPostBack) and it will bind on every page load, but this may cause more problems.


Yes as it is intuitive, i tried it earlier but it raised the problem i mentioned in Post #9 of this thread.

Ok i'll make the setRepeaterDataSource(){} method and post the results back here.
ThanQ


----------



## Jimmy444 (Sep 10, 2006)

WOW... it worked... 
I bound the Repeater by calling method "setRepeaterDataSource(){}" in method that updated the database (eventhandler of a button in repeater control) as well and it worked...
Thanks A Lot Sir! your help has been so much helpful.

I'll keep on posting in this thread 

Take Care


----------

