lossing data when changing page

Discussion in 'ASP .Net Datagrid Control' started by gh0st54, Aug 23, 2004.

  1. gh0st54

    gh0st54 Guest

    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")!=null?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(lnkBtn_Command);

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


    private void dgMessages_PageIndexChanged(object source,
    System.Web.UI.WebControls.DataGridPageChangedEventArgs e) {
    this.dgMessages.CurrentPageIndex = e.NewPageIndex;
    this.dgMessages.DataSource=this.CreateData();
    this.dgMessages.DataBind();
    }
     
    gh0st54, Aug 23, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Rodrigues

    Postback lossing Session values?

    Mark Rodrigues, Oct 22, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    478
    William LaMartin
    Nov 23, 2003
  2. Samridhi Kumar Shukla
    Replies:
    1
    Views:
    540
    Alvin Bruney
    Nov 30, 2003
  3. John Wright

    Lossing my session variable

    John Wright, Sep 7, 2007, in forum: ASP .Net
    Replies:
    4
    Views:
    434
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Sep 8, 2007
  4. Replies:
    0
    Views:
    184
  5. VK
    Replies:
    3
    Views:
    202
    Dr J R Stockton
    Mar 15, 2007
Loading...

Share This Page