Datagrid

G

Guest

hi all,

I am a newbie and i need some help.I have datagrid on my asp.net page
which has hyperlink columns.
the datagrid configuration in the aspx page is as follows

<asp:DataGrid id="dgNewsLinks" DataKeyField="News_ID" runat="server"
Width="283px" AutoGenerateColumns="False" GridLines="None" ShowHeader="False">
<Columns>
<asp:HyperLinkColumn Target="_parent" DataNavigateUrlField="url"
DataTextField="date"></asp:HyperLinkColumn>
<asp:HyperLinkColumn Target="_parent" DataNavigateUrlField="url"
DataTextField="headline"></asp:HyperLinkColumn>
</Columns>
</asp:DataGrid>

i have coded the following in the page load handler

private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
DataSet ds=PressDBGateway.getNewsLinks();
dgNewsLinks.DataSource=ds;
dgNewsLinks.DataBind();
}

The problem is when i click on the hyperlink in the datagrid i go to a new
page but when i press back button of browser to come back to the datagrid
page,the datagrid gets loaded again and appends to the existing data.So
everytime i press the back button my datagrid keeps getting bigger and bigger
as the same set of records keep getting appended to it.

What am i doing wrong?

Thanks for your time.
 
L

Lucas Tam

if(!IsPostBack)
{
DataSet ds=PressDBGateway.getNewsLinks();
dgNewsLinks.DataSource=ds;
dgNewsLinks.DataBind();
}

The problem is when i click on the hyperlink in the datagrid i go to a
new page but when i press back button of browser to come back to the
datagrid page,the datagrid gets loaded again and appends to the
existing data.So everytime i press the back button my datagrid keeps
getting bigger and bigger as the same set of records keep getting
appended to it.

What am i doing wrong?

Only bind the grid if Not Page.IsPostback.
 
G

Guest

Hi cooltech,

In your datagrid, you are using Target="_parent". If you use
Target="_blank", the new page will be in a new popup window. The datagrid
page can still keep there. So you just need to Close the new page rather
than to Back.

If you still want to keep your design., you can check method
PressDBGateway.getNewsLinks(). The trouble may come from there. You can post
code of the method, let us what happens in the method.

HTH

Elton Wang
(e-mail address removed)
 
G

Guest

Elton W said:
Hi cooltech,

In your datagrid, you are using Target="_parent". If you use
Target="_blank", the new page will be in a new popup window. The datagrid
page can still keep there. So you just need to Close the new page rather
than to Back.

If you still want to keep your design., you can check method
PressDBGateway.getNewsLinks(). The trouble may come from there. You can post
code of the method, let us what happens in the method.

HTH

Elton Wang
(e-mail address removed)
Hi,
thanks for your reply.I tried using target=_blank and i did not get the
problem.
But I cannot make the target=_blank coz I am replicating a website and it
needs to show in the same frame.So there must be some other way to do this I
hope.

i am posting the code for PressDBGateway.cs

public class PressDBGateway
{

private static string connectionString=(string
)ConfigurationSettings.AppSettings ["ConnectionString"];

private static SqlConnection sqlConn=new SqlConnection(connectionString);
private static SqlDataAdapter sqlDA=new SqlDataAdapter();
private static DataSet DSNews=new DataSet();

public PressDBGateway() { }

public static DataSet getNewsLinks()
{
SqlCommand sqlCmd=new SqlCommand();
sqlCmd.Connection=sqlConn;
sqlCmd.CommandText="getNewsLinks";
sqlCmd.CommandType=CommandType.StoredProcedure;
sqlDA.SelectCommand=sqlCmd;
sqlDA.Fill(DSNews);
sqlConn.Close();
return DSNews;
}
}
}
 
G

Guest

hi all

Thanks for your replies.
i figured out the problem
the problem was in the PRessDBGateway.cs code.
alll i had to do was call sqlDA.Clear() before i call sqlDA.Fill()
This was because i had declared the dataset as a private member variable
instead of declaring it just before i use sqlDA.FIll() in the getNewsLinks()
method

hope this helps some1 with a similar problem
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top