Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > lossing data when changing page

Reply
Thread Tools

lossing data when changing page

 
 
gh0st54
Guest
Posts: n/a
 
      08-23-2004
Hi I have an other data grid on a different page

and I have the same problem when I change page some databinding gets
lost
first page in datagrid is fine all the data is there but on the second
page the hidden txtbox is not receiving the data it should

here is the code :
------
aspx
-----
<asp:datagrid id="dgMessages" runat="server" Width="100%"
AllowPaging="True" AutoGenerateColumns="False"
CellPadding="0" BorderWidth="0px"
EnableViewState="False">
<AlternatingItemStyle HorizontalAlign="Left"
VerticalAlign="Middle" BackColor="White"></AlternatingItemStyle>
<ItemStyle BackColor="#E1F0FF"></ItemStyle>
<Columns>
<asp:TemplateColumn>
<HeaderStyle Width="5pc"
CssClass="dgHeader"></HeaderStyle>
<ItemTemplate>
<CENTER>
<asp:Image id=Image1 runat="server" ImageUrl='<%#
DataBinder.Eval(Container.DataItem,"ImagePath")!=n ull?DataBinder.Eval(Container.DataItem,"ImagePath" ):""
%>'>
</asp:Image></CENTER>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn Visible="False"
HeaderText="MessageId">
<ItemTemplate>
<asp:TextBox id=txtMsgId runat="server" Text='<%#
DataBinder.Eval(Container.DataItem,"MessageId") %>'>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Member Name">
<HeaderStyle Width="10pc"
CssClass="dgHeader"></HeaderStyle>
<ItemTemplate>
<asp:LinkButton CssClass="gridbluetext"
id="LinkButton1" runat="server" CommandArgument='<%#
DataBinder.Eval(Container.DataItem,"MessageId") %>'>
<%# DataBinder.Eval(Container.DataItem,"UserName") %>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Date/Time GMT">
<HeaderStyle Width="30pc"
CssClass="dgHeader"></HeaderStyle>
<ItemTemplate>
<asp:Label id="lblDate" runat="server" Text='<%#
DataBinder.Eval(Container.DataItem,"Date") %>'
CssClass="gridbluetext">
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="Subject"
HeaderText="Subject">
<HeaderStyle Width="50pc"
CssClass="dgHeader"></HeaderStyle>
<ItemStyle CssClass="gridbluetext"></ItemStyle>
</asp:BoundColumn>
<asp:TemplateColumn>
<HeaderStyle Width="5pc"
CssClass="dgHeader"></HeaderStyle>
<ItemStyle CssClass="gridbluetext"></ItemStyle>
<ItemTemplate>
<CENTER>
<asp:CheckBox id="chkDelete"
runat="server"></asp:CheckBox></CENTER>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn Visible="False" HeaderText="Online">
<ItemTemplate>
<asp:TextBox id="Online" runat="server" Text='<%#
DataBinder.Eval(Container.DataItem,"Online") %>'>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle HorizontalAlign="Right"
Mode="NumericPages"></PagerStyle>
</asp:datagrid>

-------
aspx.cs
--------

private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{

}
this.UpdateGrid(this.CreateData());
}

private DataSet CreateData(){
this.ssp_GetMessagesHeaders.Parameters["@MemberId"].Value= new
Guid(Session["MemberId"].ToString());//MemberId;

this.ssp_GetMessagesHeaders.Parameters["@Direction"].Value= 1;


this.ssp_GetMessagesHeaders.Parameters["@Error"].Value= null;

SqlDataAdapter daData = new SqlDataAdapter();
daData.SelectCommand = this.ssp_GetMessagesHeaders ;

DataSet ds = new DataSet();

try {
this.cnn.Open();
daData.Fill(ds);
}
catch(System.Exception ex) {
Response.Write(ex.Message);
}
finally {
this.cnn.Close();
}
return ds;
}
private void UpdateGrid(DataSet ds){
if (ds.Tables[0].Columns.Count > 1){
this.dgMessages.DataSource= ds.Tables[0];
this.dgMessages.DataBind();
this.dgMessages.Visible=true;
this.lblNoMessages.Visible=false;
this.dgMessages.Enabled=true;
}
else {
this.dgMessages.Visible=false;
this.dgMessages.Enabled=false;
this.lblNoMessages.Visible=true;
}
}

private void UpdateGrid(DataSet ds){
if (ds.Tables[0].Columns.Count > 1){
this.dgMessages.DataSource= ds.Tables[0];
this.dgMessages.DataBind();
this.dgMessages.Visible=true;
this.lblNoMessages.Visible=false;
this.dgMessages.Enabled=true;
}
else {
this.dgMessages.Visible=false;
this.dgMessages.Enabled=false;
this.lblNoMessages.Visible=true;
}
}

private void dgMessages_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e) {
if((e.Item.ItemType == wc.ListItemType.Item) ||
(e.Item.ItemType == wc.ListItemType.AlternatingItem)){

wc.LinkButton lnkBtn;
wc.TextBox txtOnline;
wc.Label lblDate;

lnkBtn = (wc.LinkButton)e.Item.FindControl("LinkButton1");
txtOnline = (wc.TextBox)e.Item.FindControl("Online");
lblDate = (wc.Label)e.Item.FindControl("lblDate");

lblDate.Text = functions.ShowDateTime(lblDate.Text.ToString());

lnkBtn.Command +=new
System.Web.UI.WebControls.CommandEventHandler(lnkB tn_Command);

if (txtOnline.Text =="True"){
lnkBtn.CssClass ="orangetext";
}
else {
lnkBtn.CssClass ="bluetext";
}
}
}


private void dgMessages_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEvent Args e) {
this.dgMessages.CurrentPageIndex = e.NewPageIndex;
this.dgMessages.DataSource=this.CreateData();
this.dgMessages.DataBind();
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
CSPEC issue: lossing scope (or incorrect scope) in cspec subroutine. balldarrens@gmail.com Perl Misc 0 02-05-2009 08:42 PM
Lossing my session variable John Wright ASP .Net 4 09-08-2007 11:49 AM
PIX 501 and 506 lossing VPN connection to remote site after timeout Jay Cisco 7 09-05-2006 10:00 PM
printer keeps lossing the driver Glennies Computer Support 3 05-25-2005 12:34 AM
Postback lossing Session values? Mark Rodrigues ASP .Net 4 11-23-2003 08:23 PM



Advertisments