Category Archives: Paging

[RESOLVED] paging

I have a webpage where I am adding UserControls on the fly depending upon number of rows in a dataset. row data feeds the usercontrol.

I want to add paging if number of usercontrols is more that 5, which in turn means if number of rows in the dataset is more than 5. It is like this forum where it pages based upon number of replies to a post.  

Any best practices?

yeah, this could be one option. I am looking for a more elegant solution. I don't want to use dropdowns for page navigation.

 

If I am not wrong then you have created one use controls for displying set of item just like one row and you are adding that contrils to show list of data (as no of rows) and now you want to establish paging for this functionality.

 

Then you can use datagird, gridview or repeater cotrol and add you user contorl in itemtemplate of dataview. 

<asp:TemplateField HeaderText="<%$ Resources:KHResource, Actions %>" >
    <ItemTemplate>
        <uc1:MyControl ID="rowMyControl" runat="server" />
         </ItemTemplate>
     <ItemStyle HorizontalAlign="Center" Width="30px" />
</asp:TemplateField>


for Paging you can set avalalbel paging for your grid view controls. no need to extra things to implement

 

Mark as answered if this is helps 

 

I need to set some properties of User Control from row data. Please suggest if this is possible with this approach. 

Hi, You can try like this .... I have used this for repeater ..you can use this for some other control alsp ...have a look ...


SqlDataAdapter da = new SqlDataAdapter(sqlstring, connection);
        DataSet ds = new DataSet();
        da.Fill(ds, "image_data");
        PagedDataSource pageds = new PagedDataSource();
        pageds.DataSource = ds.Tables["image_data"].DefaultView;
        pageds.AllowPaging = true;
        pageds.PageSize = 5;
        int curpage = 0;

        if ((Request.QueryString["Page"] != null))
        {
            curpage = Convert.ToInt32(Request.QueryString["Page"]);
        }
        else
        {
            curpage = 1;
        }

        pageds.CurrentPageIndex = curpage - 1;
        lblCurrpage.Text = "Page: " + curpage.ToString();

        if (!pageds.IsFirstPage)
        {
            lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(curpage - 1);
        }

        if (!pageds.IsLastPage)
        {
            lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(curpage + 1);
        }

        Repeater1.DataSource = pageds;

        Repeater1.DataBind();

Hi vaibhav, I am able to set the properties too in the template field method. Thanks for the inputs.  

[RESOLVED] Referencing host page controls from User Control

Hi

I want to use a dropdownlist control as paging options (50, 100, 150, 200) for a GridView control so I can reuse the user control on other pages that uses paging. The dropdownlist control will be in the user control page and the GridView will be on the host page. How do I reference the GridView control generically from the dropdownlist in the user control to set the PageSize property of the GridView control upon selecting one of the dropdownlist options. Any advice and if there are other means to accomplish such tasks to allow reusability.


I am not sure particularly with the idea of only DDL in the UserControl...instead you can have DDL along with Grid in the UC....

coming back to your question....you can expose Public property to actually communicate from UserControl to PAge....

http://www.intstrings.com/ramivemula/asp-net/jumpstart-5-access-properties-of-a-usercontrol-from-other-usercontrol-in-asp-net-page/

look at the above sample to actually get the idea of public field....

Thanks.

[RESOLVED] how to use grid view button

i have made two coloumns with title and secriptn as header text . i want to create a button for each row. the button should open up a alertbox dependng upon which row buton was clciked .how to do this.

hi,

refer : http://msdn.microsoft.com/en-us/library/bb907626.aspx

http://www.asp.net/data-access/tutorials/adding-and-responding-to-buttons-to-a-gridview-cs

http://authors.aspalliance.com/aspxtreme/webforms/controls/addingbuttonfieldstogridview.aspx

http://www.devx.com/tips/Tip/27973

use the link .......http://vbdotnetaddict.blogspot.com

<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:GridView  ID="gv" runat="server" AutoGenerateColumns="False"</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">                                            CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True" OnRowCommand="gvVehicle_RowCommand"</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">                                            Width="100%"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">                                            <Columns></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">                                                </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">                                                </asp:TemplateField></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">                                                <asp:BoundField DataField="title" HeaderText="title"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">                                                    <ItemStyle Width="60px" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">                                                </asp:BoundField></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">                                                <asp:BoundField DataField="title1" HeaderText="title1"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">                                                    <ItemStyle Width="40px" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">                                                </asp:BoundField>                                               </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">                                                <asp:TemplateField></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">                                                    <ItemTemplate></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">                                                         <asp:Button ID="btnEdit" runat="server" ToolTip="Edit" Text="Click" OnClientClick="javaScript:alert('Hi');" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">                                                    </ItemTemplate></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">                                                    <ItemStyle Width="10px" HorizontalAlign="Center" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">                                                </asp:TemplateField></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">                                              </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">                                            </Columns></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">                                        </asp:GridView>hi</div>

hi,

 try to use like this and bind gridview frm server side 

<asp:GridView  ID="gv" runat="server" AutoGenerateColumns="False"

                                            CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True" OnRowCommand="gvVehicle_RowCommand"

                                            Width="100%">

                                            <Columns>

                                                

                                                </asp:TemplateField>

                                                <asp:BoundField DataField="title" HeaderText="title">

                                                    <ItemStyle Width="60px" />

                                                </asp:BoundField>

                                                <asp:BoundField DataField="title1" HeaderText="title1">

                                                    <ItemStyle Width="40px" />

                                                </asp:BoundField>                                               

                                                <asp:TemplateField>

                                                    <ItemTemplate>

                                                         <asp:Button ID="btnEdit" runat="server" ToolTip="Edit" Text="Click" OnClientClick="javaScript:alert('Hi');" />

                                                    </ItemTemplate>

                                                    <ItemStyle Width="10px" HorizontalAlign="Center" />

                                                </asp:TemplateField>

                                              

                                            </Columns>

                                        </asp:GridView>

[RESOLVED] Can't see TreeView from code-behind code page

I have an aspx page with a TreeView control named TreeView1.  in the Page_Load method I am trying to collapse all nodes except for the current node.  I used this code in the Page_Load method:

TreeView1.CollapseAllNodes();
TreeView1.SelectedNode.Expand();

When I try to run this I get the following error:

CS0103: The name 'TreeView1' does not exist in the current context

I am using a .NET 2.0 website and can't seem to reference controls in my .aspx page from within my code-behind page. I tried adding an instance of the TreeView before my Page_Load method call in the code behind, but, it still doesn't create a reference.  What am I missing?

Assuming you haven't misspelled "TreeView1", it looks to me like your .aspx isn't connected to your code-behind.

I'd try:

  • rebuilding the entire solution
  • closing Visual Studio, rebooting computer [please, don't say it, I know, but sometimes...]
  • excluding the page in question from your solution, and then adding it in as a new item, copying markup and code from old to new

If all that fails, could you please post all your markup and code - the entirel page?  With that, I'll have a better chance at spotting something. 

(It makes things a lot more readable if you use the Insert Code tool. If you need instructions, see my How to use the Forums' "Insert Code" tool. post.) 

I have tried your suggestions and didn't get much further.  I think I am missing something a little less complex than that.  This is a .NET 2.0 site.  When I tried to reference the controls in the code-behind page I used this approach:

TreeView TreeView1 = (TreeView)Page.FindControl("TreeView1");


However, when I tried to use tab completion after typing (TreeView)Page. it would not provide the FindControl method.  Is there something about the project config I need to look at?  I have never had this much difficulty referencing code from the code-behind.

FindControl executes at run-time, and should only be used for dynamically created controls, like those inside ItemTemplates, etc.

Assuming that you've created TreeView1 using basic markup, you should be able to replace the above line with this "TreeView TreeView1 = this.TreeView1;".   Better yet, you should be able to refer directly to this.TreeView1 wherever you need to.

If this doesn't help, would you mind posting all your relevant markup and code?

The following page doesn't specifically look for TreeView1, but, it's the same problem.  I cannot see controls from the code-behind.  Here is the .aspx code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="locked_batches.aspx.cs" Inherits="Environments_Model_locked_batches" Src="~/Environments/Model/locked_batches.aspx.cs" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link href="../../Stylesheets/default.css" rel="Stylesheet" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div id="top"><span class="fiserv">eFichency</span> Reference</div>
        <div id="preferences">
            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
                onselectedindexchanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList>
        </div>
        <div id="content">
            <table>
                <tr>
                    <td>
                        <asp:SiteMapDataSource ID="SiteMapDataSource" runat="server" />
                        <asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource"
                            ImageSet="Msdn" NodeIndent="10">
                            <HoverNodeStyle BackColor="#CCCCCC" BorderColor="#888888" BorderStyle="Solid"
                                Font-Underline="True" />
                            <NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black"
                                HorizontalPadding="5px" NodeSpacing="1px" VerticalPadding="2px" />
                            <ParentNodeStyle Font-Bold="False" />
                            <SelectedNodeStyle BackColor="White" BorderColor="#888888" BorderStyle="Solid"
                                BorderWidth="1px" Font-Underline="False" HorizontalPadding="3px"
                                VerticalPadding="1px" />
                        </asp:TreeView>
                    </td>
                    <td>
			            Find below information on locked batches.<br/><br/>
                        <asp:Label ID="LabelCount" runat="server" Text="The record count is: "></asp:Label><br /><br />
                        <asp:SqlDataSource ID="sqlDataSource" runat="server"
                            SelectCommand="SELECT [AppID], [BatchID], [UserBatchName], [LastEventDate], [Message], [LockedUserID] FROM [Batch] WHERE (([CurrentEventTypeID] = @CurrentEventTypeID) AND ([Received] = @Received))"
                            connectionString="<%$ ConnectionStrings:ModelFOTNIndexConnectionString %>"
                            onselected="SqlDataSource_Selected">
                            <SelectParameters>
                                <asp:Parameter DefaultValue="10" Name="CurrentEventTypeID" Type="Int32" />
                                <asp:Parameter DefaultValue="2" Name="Received" Type="Int32" />
                            </SelectParameters>
                        </asp:SqlDataSource>
                        <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
                            AllowSorting="True" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None"
                            BorderWidth="1px" CellPadding="4" DataSourceID="SqlDataSource"
                            ForeColor="Black" GridLines="Vertical" PageSize="15" Visible="True"
                            onpageindexchanged="GridView1_PageIndexChanged" onsorted="GridView1_Sorted" >
                            <RowStyle BackColor="#F7F7DE" />
                            <EmptyDataTemplate>
                                No records were found.
                            </EmptyDataTemplate>
                            <FooterStyle BackColor="#CCCC99" />
                            <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
                            <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
                            <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
                            <AlternatingRowStyle BackColor="White" />
                        </asp:GridView>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    </form>
</body>
</html>


And, here is the code-behind:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

public partial class Environments_Model_locked_batches : System.Web.UI.Page
{
		protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DropDownList1.DataSource = IndexDataSource(sqlDataSource);
            DropDownList1.DataBind();
            DropDownList1.Items.Insert(0, "Choose a filter string");
        }
    }

    protected ArrayList IndexDataSource(SqlDataSource sqlDataSource)
    {
        ArrayList indexArrayList = new ArrayList();
        DataTable indexDataTable = new DataTable();
        DataView indexDataView = new DataView();

        indexDataView = (DataView)sqlDataSource.Select(DataSourceSelectArguments.Empty);
        indexDataTable = indexDataView.ToTable();

        foreach (DataRow dataRow in indexDataTable.Rows)
        {
            string[] rowIndex = (dataRow["UserBatchName"].ToString()).Split(' ');
            foreach (string word in rowIndex)
            {
                if (!indexArrayList.Contains(word))
                {
                    indexArrayList.Add(word);
                }
            }
        }

        indexArrayList.Sort();

        return indexArrayList;
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedValue == "Choose a filter string")
        {
            GridView1.Visible = true;
            GridView1.DataBind();
        }
        else
        {
            sqlDataSource.SelectParameters.Clear();
            sqlDataSource.SelectParameters.Add("UserBatchName", DropDownList1.SelectedValue);
            sqlDataSource.SelectCommand = "SELECT [AppID], [BatchID], [UserBatchName], [LastEventDate], [Message], [LockedUserID] FROM [Batch] WHERE (([CurrentEventTypeID] = @CurrentEventTypeID) AND ([Received] = @Received) OR (UserBatchName LIKE '% ' + @UserBatchName) OR (UserBatchName LIKE @UserBatchName + ' %') OR (UserBatchName LIKE '% ' + @UserBatchName + ' %') OR (UserBatchName = @UserBatchName))";
            GridView1.DataBind();
        }
    }

    protected void GridView1_PageIndexChanged(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedValue == "Choose a filter string")
        {
            GridView1.Visible = true;
            GridView1.DataBind();
        }
        else
        {
            sqlDataSource.SelectParameters.Clear();
            sqlDataSource.SelectParameters.Add("UserBatchName", DropDownList1.SelectedValue);
            sqlDataSource.SelectCommand = "SELECT [AppID], [BatchID], [UserBatchName], [LastEventDate], [Message], [LockedUserID] FROM [Batch] WHERE (([CurrentEventTypeID] = @CurrentEventTypeID) AND ([Received] = @Received) OR (UserBatchName LIKE '% ' + @UserBatchName) OR (UserBatchName LIKE @UserBatchName + ' %') OR (UserBatchName LIKE '% ' + @UserBatchName + ' %') OR (UserBatchName = @UserBatchName))";
            GridView1.DataBind();
        }
    }

    protected void GridView1_Sorted(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedValue == "Choose a filter string")
        {
            GridView1.Visible = true;
            GridView1.DataBind();
        }
        else
        {
            sqlDataSource.SelectParameters.Clear();
            sqlDataSource.SelectParameters.Add("UserBatchName", DropDownList1.SelectedValue);
            sqlDataSource.SelectCommand = "SELECT [AppID], [BatchID], [UserBatchName], [LastEventDate], [Message], [LockedUserID] FROM [Batch] WHERE (([CurrentEventTypeID] = @CurrentEventTypeID) AND ([Received] = @Received) OR (UserBatchName LIKE '% ' + @UserBatchName) OR (UserBatchName LIKE @UserBatchName + ' %') OR (UserBatchName LIKE '% ' + @UserBatchName + ' %') OR (UserBatchName = @UserBatchName))";
            GridView1.DataBind();
        }
    }
    protected void SqlDataSource_Selected(object sender, SqlDataSourceStatusEventArgs e)
    {
        if (DropDownList1.SelectedValue == "Choose a filter string")
        {
            LabelCount.Text = "The record count for all records is: " + e.AffectedRows.ToString();
        }
        else
        {
            LabelCount.Text = "The record count for " + DropDownList1.SelectedValue + " is: " + e.AffectedRows.ToString();
        }

        if (e.Exception != null)
        {
            LabelCount.Visible = false;
            GridView1.EmptyDataText = e.Exception.Message;
        }
    }
}


When I try to run the page, I get this:

Server Error in '/' Application.
--------------------------------------------------------------------------------

Compilation Error 
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS0103: The name 'DropDownList1' does not exist in the current context

Source Error:

 

Line 15:         if (!IsPostBack)
Line 16:         {
Line 17:             DropDownList1.DataSource = IndexDataSource(sqlDataSource);
Line 18:             DropDownList1.DataBind();
Line 19:             DropDownList1.Items.Insert(0, "Choose a filter string");
 

Source File: c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs    Line: 17 



Show Detailed Compiler Output:


c:\windows\system32\inetsrv> "c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc.exe" /t:library /utf8output /R:"C:\WINDOWS\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll" /R:"c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.WorkflowServices\3.5.0.0__31bf3856ad364e35\System.WorkflowServices.dll" /R:"C:\WINDOWS\assembly\GAC_32\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll" /R:"C:\WINDOWS\assembly\GAC_32\System.Web\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Mobile\2.0.0.0__b03f5f7f11d50a3a\System.Web.Mobile.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Runtime.Serialization\3.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.IdentityModel\3.0.0.0__b77a5c561934e089\System.IdentityModel.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.ServiceModel\3.0.0.0__b77a5c561934e089\System.ServiceModel.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.ServiceModel.Web\3.5.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Services\2.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /out:"c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\f3c5e0e5\97ac95d6\App_Web_locked_batches.aspx.cs.d4225d1c.bewrivva.dll" /debug- /optimize+ /w:4 /nowarn:1659;1699;1701  "c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\f3c5e0e5\97ac95d6\App_Web_locked_batches.aspx.cs.d4225d1c.bewrivva.0.cs" "c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\f3c5e0e5\97ac95d6\App_Web_locked_batches.aspx.cs.d4225d1c.bewrivva.1.cs"


Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.3053
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.

c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(17,13): error CS0103: The name 'DropDownList1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(17,56): error CS0103: The name 'sqlDataSource' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(18,13): error CS0103: The name 'DropDownList1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(19,13): error CS0103: The name 'DropDownList1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(51,13): error CS0103: The name 'DropDownList1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(53,13): error CS0103: The name 'GridView1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(54,13): error CS0103: The name 'GridView1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(58,13): error CS0103: The name 'sqlDataSource' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(59,13): error CS0103: The name 'sqlDataSource' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(59,65): error CS0103: The name 'DropDownList1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(60,13): error CS0103: The name 'sqlDataSource' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(61,13): error CS0103: The name 'GridView1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(67,13): error CS0103: The name 'DropDownList1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(69,13): error CS0103: The name 'GridView1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(70,13): error CS0103: The name 'GridView1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(74,13): error CS0103: The name 'sqlDataSource' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(75,13): error CS0103: The name 'sqlDataSource' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(75,65): error CS0103: The name 'DropDownList1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(76,13): error CS0103: The name 'sqlDataSource' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(77,13): error CS0103: The name 'GridView1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(83,13): error CS0103: The name 'DropDownList1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(85,13): error CS0103: The name 'GridView1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(86,13): error CS0103: The name 'GridView1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(90,13): error CS0103: The name 'sqlDataSource' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(91,13): error CS0103: The name 'sqlDataSource' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(91,65): error CS0103: The name 'DropDownList1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(92,13): error CS0103: The name 'sqlDataSource' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(93,13): error CS0103: The name 'GridView1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(98,13): error CS0103: The name 'DropDownList1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(100,13): error CS0103: The name 'LabelCount' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(104,13): error CS0103: The name 'LabelCount' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(104,57): error CS0103: The name 'DropDownList1' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(109,13): error CS0103: The name 'LabelCount' does not exist in the current context
c:\Inetpub\wwwroot\reference\Environments\Model\locked_batches.aspx.cs(110,13): error CS0103: The name 'GridView1' does not exist in the current context

 



Show Complete Compilation Source:


Line 1:    using System;
Line 2:    using System.Collections;
Line 3:    using System.Collections.Generic;
Line 4:    using System.Data;
Line 5:    using System.Data.SqlClient;
Line 6:    using System.Web;
Line 7:    using System.Web.UI;
Line 8:    using System.Web.UI.HtmlControls;
Line 9:    using System.Web.UI.WebControls;
Line 10:   
Line 11:   public partial class Environments_Model_locked_batches : System.Web.UI.Page
Line 12:   {
Line 13:   		protected void Page_Load(object sender, EventArgs e)
Line 14:       {
Line 15:           if (!IsPostBack)
Line 16:           {
Line 17:               DropDownList1.DataSource = IndexDataSource(sqlDataSource);
Line 18:               DropDownList1.DataBind();
Line 19:               DropDownList1.Items.Insert(0, "Choose a filter string");
Line 20:           }
Line 21:       }
Line 22:   
Line 23:       protected ArrayList IndexDataSource(SqlDataSource sqlDataSource)
Line 24:       {
Line 25:           ArrayList indexArrayList = new ArrayList();
Line 26:           DataTable indexDataTable = new DataTable();
Line 27:           DataView indexDataView = new DataView();
Line 28:   
Line 29:           indexDataView = (DataView)sqlDataSource.Select(DataSourceSelectArguments.Empty);
Line 30:           indexDataTable = indexDataView.ToTable();
Line 31:   
Line 32:           foreach (DataRow dataRow in indexDataTable.Rows)
Line 33:           {
Line 34:               string[] rowIndex = (dataRow["UserBatchName"].ToString()).Split(' ');
Line 35:               foreach (string word in rowIndex)
Line 36:               {
Line 37:                   if (!indexArrayList.Contains(word))
Line 38:                   {
Line 39:                       indexArrayList.Add(word);
Line 40:                   }
Line 41:               }
Line 42:           }
Line 43:   
Line 44:           indexArrayList.Sort();
Line 45:   
Line 46:           return indexArrayList;
Line 47:       }
Line 48:   
Line 49:       protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
Line 50:       {
Line 51:           if (DropDownList1.SelectedValue == "Choose a filter string")
Line 52:           {
Line 53:               GridView1.Visible = true;
Line 54:               GridView1.DataBind();
Line 55:           }
Line 56:           else
Line 57:           {
Line 58:               sqlDataSource.SelectParameters.Clear();
Line 59:               sqlDataSource.SelectParameters.Add("UserBatchName", DropDownList1.SelectedValue);
Line 60:               sqlDataSource.SelectCommand = "SELECT [AppID], [BatchID], [UserBatchName], [LastEventDate], [Message], [LockedUserID] FROM [Batch] WHERE (([CurrentEventTypeID] = @CurrentEventTypeID) AND ([Received] = @Received) OR (UserBatchName LIKE '% ' + @UserBatchName) OR (UserBatchName LIKE @UserBatchName + ' %') OR (UserBatchName LIKE '% ' + @UserBatchName + ' %') OR (UserBatchName = @UserBatchName))";
Line 61:               GridView1.DataBind();
Line 62:           }
Line 63:       }
Line 64:   
Line 65:       protected void GridView1_PageIndexChanged(object sender, EventArgs e)
Line 66:       {
Line 67:           if (DropDownList1.SelectedValue == "Choose a filter string")
Line 68:           {
Line 69:               GridView1.Visible = true;
Line 70:               GridView1.DataBind();
Line 71:           }
Line 72:           else
Line 73:           {
Line 74:               sqlDataSource.SelectParameters.Clear();
Line 75:               sqlDataSource.SelectParameters.Add("UserBatchName", DropDownList1.SelectedValue);
Line 76:               sqlDataSource.SelectCommand = "SELECT [AppID], [BatchID], [UserBatchName], [LastEventDate], [Message], [LockedUserID] FROM [Batch] WHERE (([CurrentEventTypeID] = @CurrentEventTypeID) AND ([Received] = @Received) OR (UserBatchName LIKE '% ' + @UserBatchName) OR (UserBatchName LIKE @UserBatchName + ' %') OR (UserBatchName LIKE '% ' + @UserBatchName + ' %') OR (UserBatchName = @UserBatchName))";
Line 77:               GridView1.DataBind();
Line 78:           }
Line 79:       }
Line 80:   
Line 81:       protected void GridView1_Sorted(object sender, EventArgs e)
Line 82:       {
Line 83:           if (DropDownList1.SelectedValue == "Choose a filter string")
Line 84:           {
Line 85:               GridView1.Visible = true;
Line 86:               GridView1.DataBind();
Line 87:           }
Line 88:           else
Line 89:           {
Line 90:               sqlDataSource.SelectParameters.Clear();
Line 91:               sqlDataSource.SelectParameters.Add("UserBatchName", DropDownList1.SelectedValue);
Line 92:               sqlDataSource.SelectCommand = "SELECT [AppID], [BatchID], [UserBatchName], [LastEventDate], [Message], [LockedUserID] FROM [Batch] WHERE (([CurrentEventTypeID] = @CurrentEventTypeID) AND ([Received] = @Received) OR (UserBatchName LIKE '% ' + @UserBatchName) OR (UserBatchName LIKE @UserBatchName + ' %') OR (UserBatchName LIKE '% ' + @UserBatchName + ' %') OR (UserBatchName = @UserBatchName))";
Line 93:               GridView1.DataBind();
Line 94:           }
Line 95:       }
Line 96:       protected void SqlDataSource_Selected(object sender, SqlDataSourceStatusEventArgs e)
Line 97:       {
Line 98:           if (DropDownList1.SelectedValue == "Choose a filter string")
Line 99:           {
Line 100:              LabelCount.Text = "The record count for all records is: " + e.AffectedRows.ToString();
Line 101:          }
Line 102:          else
Line 103:          {
Line 104:              LabelCount.Text = "The record count for " + DropDownList1.SelectedValue + " is: " + e.AffectedRows.ToString();
Line 105:          }
Line 106:  
Line 107:          if (e.Exception != null)
Line 108:          {
Line 109:              LabelCount.Visible = false;
Line 110:              GridView1.EmptyDataText = e.Exception.Message;
Line 111:          }
Line 112:      }
Line 113:  }
 




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3615; ASP.NET Version:2.0.50727.3618 


Anywhere I have a control from the .aspx page, it shows the same error.  This is just the first control reference it encounters.

Will,

I must admit I'm pretty stumped.  Somehow, the .aspx and the code-behind aren't finding each other.

There's one thing I notice about your page that's different from mine.  In the <@Page> directive, you have a "Src=" attribute that my pages never have.  According to this MSDN article:

"You can use the Src attribute to link build providers to the page. For more information, see the BuildProvider class. Also, in versions of ASP.NET prior to 2.0, the Src attribute was used as an alternative way to link a code-behind file to a page. In ASP.NET 2.0, the preferred approach to linking a code-behind source file to a page is to use the Inherits attribute to specify a class, along with the CodeFile attribute to specify the path to the source file for the class."

That's something I've never needed, and I suggest that you try removing it.

I am beginning to this machine has some gremlins.  I use the Src attribute as a workaround to compiler issue.  It was saying it couldn't find the .cs file.  When I added the Src attribute, which I had never used either, it worked fine.  I am positive I have the site set to ASP.NET 2.0 in IIS, so, I don't think it's a version issue.  If I can't get it figured out soon, I might request a different box.  There are all sorts of weird things on this machine that make no sense.  I just wanted to be sure I wasn't overlooking something obvious.

Will,

Did you try taking the Src back out?

Your CodeFile attribute is where you should resolve the "couldn't find the .cs file" issue.  Based on what's in your <@Page> directive, your code must be in a file named "locked_batches.aspx.cs" which must be in the same directory as the .aspx.

Let me know.

 

AHA! I found another possible fix.

The same MSDN page says:

"[CodeFile] is used for Web site projects. The CodeBehind attribute is used for Web application projects."

In other words, if you are creating a Web Application (as opposed to a Web Site) you should change "CodeFile" to "CodeBehind" in your <@Page>.

[RESOLVED] how to pass the id of selected checkboxes to another page using query string

hi everyone,

 

i have used a gridview and checkbox to select the items in the gridview....I can select the values easily...when i am selecting one row at a time then using query string i can easily pass the id of the selected row but when i am selecting multiple rows in the field,i dont know how to pass the array of integers[i.e id value to another field]........plz help....

here is a part of my code...this is the html code....

<body>
    <form id="form1" runat="server">
        <asp:GridView ID="gvCheckboxes" runat="server" AutoGenerateColumns="False" Style="z-index: 100;
            left: 256px; position: absolute; top: 101px"   DataKeyNames="IMAGE_ID"   OnPageIndexChanging = "OnPaging"  PageSize = "10" OnRowDataBound="GridView1_RowDataBound" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" Width="422px" ShowFooter="True">
            <Columns>
             <asp:TemplateField HeaderText="Select">
           
                   
                   
            <ItemTemplate>
                      <asp:CheckBox ID="CheckBox1" runat="server" onclick = "Check_Click(this)"  Value='<%# Eval("IMAGE_ID") %>' AutoPostBack="True"/>
            </ItemTemplate>
           
                   <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
                    <HeaderTemplate>
                        <asp:CheckBox ID="chkAll"  runat="server" onclick = "checkAll(this);" />
                    </HeaderTemplate>
                    <FooterTemplate>
                    <asp:Button ID="ButtonSelect" runat="server"  OnClick="ButtonSelect_Click" Text="SELECT IMAGE"
                    />
         
                    </FooterTemplate>
                </asp:TemplateField>
               
                <asp:BoundField DataField="IMAGE_ID" HeaderText="IMAGE_ID" />
                <asp:BoundField DataField="IMAGE_SIZE" HeaderText="IMAGE_SIZE" />
                <asp:BoundField DataField="IMAGE_TYPE" HeaderText="IMAGE_TYPE" />
                <asp:TemplateField HeaderText="IMAGE">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%#"Handler.ashx?id=" + Eval("IMAGE_ID") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Image ID="Image1" runat="server" ImageUrl='<%# "Handler.ashx?id=" + Eval("IMAGE_ID") %>' />
                       
                    </ItemTemplate>
                    <ControlStyle Height="100px" Width="100px" />
                   
                </asp:TemplateField>
               
            </Columns>
        </asp:GridView>

 

here is the back end code....where if i pass the single row selected id ...then its working...
    protected void ButtonSelect_Click(object sender, EventArgs e)
    {
       
       foreach (GridViewRow row in gvCheckboxes.Rows)
        {
            //Find CheckBox
            CheckBox cb = (CheckBox)row.FindControl("CheckBox1");
            if (cb.Checked)
            {
                ImageIDs=(gvCheckboxes.DataKeys[row.RowIndex].Value.ToString());
               // ImageIDs.Add(gvCheckboxes.DataKeys[row.RowIndex].Value.ToString());
            }
        }

        //get all imageIds to string....
        //string allImageIds = String.Join(",", ImageIDs);
        //    String.Join(",", ImageIDs);
        imageid = Convert.ToInt32(allImageIds);
        ViewState["CurrentRequestID"] = imageid;
        imageid = Convert.ToInt32(ViewState["CurrentRequestID"]);
      
        Response.Redirect("ADMIN_SELECT_LOGO.aspx?Name=" + Name + "&imageid=" +imageid );
       
    }

plz tell me how to pass selected row id[which is integer] to next page

Hi,

Why don't you pass the list in a session variable instead of query string

Session["SelectedIDs"] = list of IDs

hi hassan...when i am passing the selected Ids using Session then also it is  passing only one selected id at a time....how to pass the array of integers here??

List<int> selectedIDs = new List<int>();

for (int i = 0; i < 10; i++)
     selectedIDs.Add(i);

Session["SelectedIDs"] = selectedIDs;

And get these IDs from the other page like this

List<int> selectedIDs = (List<int>)Session["SelectedIDs"];