Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

Repeater Control

  Asked By: Bailey    Date: May 19    Category: Asp.net    Views: 2245
  

I need help with the Repeater control. I am populating TextBoxes inside a
repeater with data and I want to post that data to another page using
Server.Transfer method but it is giving me the following error: Object
reference not set to an instance of an object. Any thoughts? I tried this
technique without the Repeater and it works fine. It seems that on Postback
the code behind does not see the repeater even though I am binding the data
before using Server.Transfer.

Share: 

 

16 Answers Found

 
Answer #1    Answered By: Amir Shaikh     Answered On: May 19

Please proivide the code  you are using.

 
Answer #2    Answered By: Abriana Rossi     Answered On: May 19

here is the code:

Sending Page code  Behind


private void Page_Load(object sender, System.EventArgs e)

{

int PKList = 1870007;

SqlConnection strConn = new
SqlConnection(ConfigurationSettings.AppSettings["connString"].ToString());

string strSP = "Glasseye.ap_GetAccountInformationForPlayerPrimaryKeyList "+
PKList + ", null";

SqlCommand cmd = new SqlCommand(strSP, strConn);

strConn.Open();

SqlDataReader dtrCat = cmd.ExecuteReader();

acct.DataSource = dtrCat;

acct.DataBind();

strConn.Close();

}

public string CasinoName1 { get { return CasinoName.Text; } }

public string First1 { get { return First.Text; } }



#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

InitializeComponent();

base.OnInit(e);

}



/// <summary>

/// Required method  for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

public void Button1_Click(object sender, System.EventArgs e)

{

Server.Transfer("b.aspx");

}

Receiving Page Code Behind:

namespace enterprise

{

public class b : System.Web.UI.Page

{



public a fp;



private void Page_Load(object sender, System.EventArgs e)

{

if (!IsPostBack)

{

fp = (a)Context.Handler;

Response.Write(fp.First1);

}

}



#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}



private void InitializeComponent()

{

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

}

}

 
Answer #3    Answered By: Mario Ryan     Answered On: May 19

www.denisbauer.com/.../...ControlsPlaceholder.aspx
is your answer..... perhaps..... So textbox would exist on other side of
postback.

 
Answer #4    Answered By: Garry Sanchez     Answered On: May 19

I am not creating this dynamically, any other suggestions? Here is the
WebForm page:


<form runat="server" ID="Form1">
<asp:repeater id="acct" runat="server">
<ItemTemplate>
<table width="199" align="left">
<tr>
<td align="left">
<asp:TextBox ID="CasinoName"
Runat="server">Hello</asp:TextBox>
<asp:TextBox ID="First"
Runat="server">First</asp:TextBox>
<asp:Button Runat="server" Text="Button1"
ID="Button1" NAME="Button1" onclick="Button1_Click"></asp:Button>
</td>
</tr>
</table>
</ItemTemplate>
</asp:repeater>
</form>

 
Answer #5    Answered By: Chung Tran     Answered On: May 19

How is server.transfer getting it to other page. Technically anything
created in a repeater  is child of repeater not page  if that helps....

 
Answer #6    Answered By: Salvador Alexander     Answered On: May 19

The button is calling onclick event that runs this:
public void Button1_Click(object sender, System.EventArgs e)

{

Server.Transfer("b.aspx");

}

Is their a better way to transfer  textbox data inside  a repeater  to another
page?

 
Answer #7    Answered By: Andrew Bryant     Answered On: May 19

How about using session state or view state to
transfer the stuff ?

 
Answer #8    Answered By: Becky Baker     Answered On: May 19

There is a good article in this month's aspPro.NET magazine talking about
server.transfer and server.execute. I think that the basic feeling is that
with asp.net there are many other better ways to accomplish what you used to
use the server.transfer and server.execute for.



I just wanted to chime in here incase anybody wanted to learn more about
what the server.transfer and server.execute are and what they can be used
for.

 
Answer #9    Answered By: Stacie Martin     Answered On: May 19

Ok problem is simple.

The textboxes  dont get created till after databinding phase.

If OnPrerender would be when those textboxes exist and Deinns control  would
come in handy. Anything inside  a repeater  or anything databaound for all
practical purposes is creating something dynamically.

 
Answer #10    Answered By: Adali Fischer     Answered On: May 19

I would like to use an <asp:Repeater> tag to display a list of news
items. The News items are coming from a sql server  2005 database with:

ID (int) pk
Title (varchar)
Story (varchar)
PublishDate (datetime)
ExpireDate (datetime)
link (varchar)

I would like to display using template. I would however, put an <a
href> tag in between the <li> if the Link item isn't null. I would
also like to set  the css on the <li> table if the publish date is
today... I am really lost on this one though. Any links or insight
would be appreciated

<ul>
<li></li>
</ul>

Protected Sub IntronNewsItems_ItemCommand(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles
IntronNewsItems.ItemDataBound

'Do something

End Sub

 
Answer #11    Answered By: Olga Kates     Answered On: May 19

Stupid dataBinding tricks will get you straight.

learnasp.com/freebook/learn/databindingtricks.aspx

 
Answer #12    Answered By: Milind Mishra     Answered On: May 19

I am using ASP.Net, VB2003.

I have a repeater  control.
In the ItemTemplate section of the control, my code  is:


<TD><FONT size="1"><%#getEditLink((DataBinder.Eval
(Container.dataitem, "AppID")), DataBinder.Eval
(Container.dataitem, "Relocatable"))%></FONT></TD>

<TD><FONT size="1"><%#getAddLink((DataBinder.Eval
(Container.dataitem, "AppID")), DataBinder.Eval
(Container.dataitem, "Relocatable"))%></FONT></TD>

<TD><FONT size="1"><%#getDelLink((DataBinder.Eval
(Container.dataitem, "AppID")), DataBinder.Eval
(Container.dataitem, "Relocatable"))%></FONT></TD>

In the code behind, during the page  load event, a proc
called "getData" is called.
If the query in getData returns a record, everything is ok.
If the query returns 0 records, then I need to display

<TD><FONT size="1"><%#getNoRecordsLink((DataBinder.Eval
(Container.dataitem, "AppID")), DataBinder.Eval
(Container.dataitem, "Relocatable"))%></FONT></TD>

But I dont know where to put the "If sqlreader.hasrecords" statement.

Any ideas?

 
Answer #13    Answered By: Jamie Williams     Answered On: May 19

You can just do an onbind event of the repeater.... mock code  here but if
repeater has no rows then repeater.visible = false and assign your text "No
Records" to a label or something outside of repeater.

 
Answer #14    Answered By: Darrell Harvey     Answered On: May 19

This doesnt help.
In the getAddLink method, there is a html link that is being returned.
The ItemDataBound event is xecuted before the html is built.

 
Answer #15    Answered By: Bethany Hughes     Answered On: May 19

It would be useful to see your code  behind.

 
Answer #16    Answered By: Herbert Weaver     Answered On: May 19

I didn't read it well. I was thinking you had NO records for
the repeater.... okay so in your getadlink function can't you just return a
specific string is the value='' or isnull

WAIT ... .I just looked at your code  ... why is that running through a
function - is it generating different links based on the appid? why don't
you just do something like

<a href=myeditlink.asp?ID=<%# eval("appid")%> for the EDIT line and then
something similar for the others... and if there is no appid is there still
a row?

I think Dean is right ... I think we need to see code behind.

 
Didn't find what you were looking for? Find more on Repeater Control Or get search suggestion and latest updates.




Tagged: