Click here to Skip to main content
16,014,591 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionBest CMS for .net applications Pin
riya319-Jul-09 21:17
riya319-Jul-09 21:17 
AnswerRe: Best CMS for .net applications Pin
K03069-Jul-09 21:26
K03069-Jul-09 21:26 
GeneralRe: Best CMS for .net applications Pin
riya319-Jul-09 21:35
riya319-Jul-09 21:35 
GeneralRe: Best CMS for .net applications Pin
K03069-Jul-09 21:40
K03069-Jul-09 21:40 
GeneralRe: Best CMS for .net applications Pin
riya319-Jul-09 21:40
riya319-Jul-09 21:40 
AnswerRe: Best CMS for .net applications Pin
Enver Maroshi9-Jul-09 22:02
Enver Maroshi9-Jul-09 22:02 
AnswerRe: Best CMS for .net applications Pin
Vasudevan Deepak Kumar10-Jul-09 2:37
Vasudevan Deepak Kumar10-Jul-09 2:37 
Questioncustom paging 'next/previous with numeric' Pin
pupilstuff9-Jul-09 21:16
pupilstuff9-Jul-09 21:16 
hi guys i just want to perform custom paging in which at the footer of the grid view ,there must be a pager 'pervious/next with numeric'

this is what i did

[SIZE="4"][B]in aspx page[/B] [/SIZE]




<asp:GridView ID="TableGridView"

OnPageIndexChanging="TableGridView_PageIndexChanging"
runat="server" AutoGenerateColumns="False"
AllowPaging="True" AllowSorting="True" >

</asp:GridView>

<asp:Button ID="btnConnect" runat="server" Style="z-index: 113;
left: 260px; position: absolute; top: 143px" Text="Connect & Populate" OnClick="btnConnect_Click" />

[B][SIZE="4"]in code behind page [/SIZE][/B]

public partial class _Default : System.Web.UI.Page
{

public static DataTable Table = new DataTable();
ArrayList ParameterArray = new ArrayList();


protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack && (bool)Session["IsConnectionInfoSet"]==true)
CreateTemplatedGridView();

}

protected void TableGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
//CreateTemplatedGridView();
TableGridView.PageIndex = e.NewPageIndex;
TableGridView.DataBind();
}


protected void btnConnect_Click(object sender, EventArgs e)
{
Session["IsConnectionInfoSet"] = true;
CreateTemplatedGridView();
}

void PopulateDataTable()
{
Table = new DataTable();
TableGridView.Columns.Clear();

SqlDataAdapter adapter = new SqlDataAdapter("select * from customer", "Data Source=OPWFMS-7KYGZ7SB;Initial Catalog=Mayank;User ID=sa;Password=sa");
adapter.Fill(Table);

}
void CreateTemplatedGridView()
{
// fill the table which is to bound to the GridView
PopulateDataTable();
// add templated fields to the GridView
TemplateField BtnTmpField = new TemplateField();
BtnTmpField.ItemTemplate =
new DynamicallyTemplatedGridViewHandler(ListItemType.Item, "...", "Command");
BtnTmpField.HeaderTemplate =

new DynamicallyTemplatedGridViewHandler(ListItemType.EditItem, "...", "Command");
TableGridView.Columns.Add(BtnTmpField);

for (int i = 0; i < Table.Columns.Count; i++)
{

TemplateField ItemTmpField = new TemplateField();
// create HeaderTemplate
ItemTmpField.HeaderTemplate = new DynamicallyTemplatedGridViewHandler(ListItemType.Header,
Table.Columns[i].ColumnName,
Table.Columns[i].DataType.Name);
// create ItemTemplate
ItemTmpField.ItemTemplate = new DynamicallyTemplatedGridViewHandler(ListItemType.Item,
Table.Columns[i].ColumnName,
Table.Columns[i].DataType.Name);
//create EditItemTemplate

// then add to the GridView
TableGridView.Columns.Add(ItemTmpField);

}

// bind and display the data
TableGridView.DataSource = Table;
TableGridView.DataBind();
}



}

[SIZE="4"][B]and in the class file[/B][/SIZE]

public class DynamicallyTemplatedGridViewHandler : ITemplate
{

ListItemType ItemType;
string FieldName;
string InfoType;

public DynamicallyTemplatedGridViewHandler(ListItemType item_type, string field_name, string info_type)
{
ItemType = item_type;
FieldName = field_name;
InfoType = info_type;
}

public void InstantiateIn(System.Web.UI.Control Container)
{
switch (ItemType)
{
case ListItemType.Header:
Literal header_ltrl = new Literal();
header_ltrl.Text = "<b>" + FieldName + "</b>";
Container.Controls.Add(header_ltrl);
break;
case ListItemType.Item:
switch (InfoType)
{
case "Command":
break;

default:
Label field_lbl = new Label();
field_lbl.ID = FieldName;
field_lbl.Text = String.Empty; //we will bind it later through 'OnDataBinding' event
field_lbl.DataBinding += new EventHandler(OnDataBinding);
Container.Controls.Add(field_lbl);
break;
}
break;
}
}

private void OnDataBinding(object sender, EventArgs e)
{

object bound_value_obj = null;
Control ctrl = (Control)sender;
IDataItemContainer data_item_container = (IDataItemContainer)ctrl.NamingContainer;
bound_value_obj = DataBinder.Eval(data_item_container.DataItem, FieldName);
switch (ItemType)
{
case ListItemType.Item:
Label field_ltrl = (Label)sender;
field_ltrl.Text = bound_value_obj.ToString();
break;
}

}

}
[SIZE="4"][B]but for my requirements I want to use that code [/B][/SIZE]

class NumericWithNext : ITemplate
{

GridView localGrid;
int intSlotNo = 0;

#region CONTRUCTOR

public NumericWithNext(GridView gv)
{
localGrid = gv;
//intSlotNo = slotNo;
intSlotNo = localGrid.PageIndex / 10;

//constructor
}
public void InstantiateIn(Control container)
{
LinkButton prevTenRecords = new LinkButton();
prevTenRecords.Text = "Previous 10 Pages";
prevTenRecords.CssClass = "PagingLnks";
prevTenRecords.CommandArgument = ((intSlotNo - 1) * 10 + 1).ToString(); ;
prevTenRecords.CommandName = "Page";
//prevTenRecords.Click += new EventHandler(prevTenRecords_Click);
prevTenRecords.Width = Unit.Pixel(125);
if (intSlotNo > 0)
{
container.Controls.Add(prevTenRecords);
}

LinkButton nextTenRecords = new LinkButton();
nextTenRecords.Text = "Next 10 Pages";
nextTenRecords.CommandName = "Page";
nextTenRecords.CommandArgument = ((intSlotNo + 1) * 10 + 1).ToString();
// nextTenRecords.Click += new EventHandler(nextTenRecords_Click);
nextTenRecords.CssClass = "PagingLnks";
nextTenRecords.Width = Unit.Pixel(118);
// nextTenRecords.Visible = false;



LinkButton prev = new LinkButton();
prev.Text = "Previous Page";
prev.CssClass = "PagingLnks";
prev.CommandArgument = "Prev";
prev.CommandName = "Page";
prev.Width = Unit.Pixel(90);
if (localGrid.PageIndex > 0)
{
container.Controls.Add(prev);
}

//for (int pagenum = 1; pagenum <= localGrid.PageCount; pagenum++)
for (int pagenum = (intSlotNo*10)+1; pagenum <= (intSlotNo+1)*10; pagenum++)
{
if (pagenum > localGrid.PageCount)
{
nextTenRecords.Visible = false;
break;
}
LinkButton pageInd = new LinkButton();
if (pagenum == localGrid.PageIndex + 1)
{
//pageInd.ForeColor = System.Drawing.Color.Green;PagingSelected
pageInd.CssClass = "PagingSelected";
}
else
{
pageInd.CssClass = "PagingLnks";
}
pageInd.ID = "PageInd_" + pagenum;
pageInd.Text = pagenum.ToString();
pageInd.CommandName = "Page";
pageInd.CommandArgument = pagenum.ToString();
container.Controls.Add(pageInd);
pageInd.Width = Unit.Pixel(10);
}

LinkButton next = new LinkButton();
next.Text = " Next Page";
next.CommandName="Page";
next.CommandArgument = "Next";
next.CssClass = "PagingLnks";
next.Width = Unit.Pixel(80);
if (localGrid.PageIndex < localGrid.PageCount - 1)
{
container.Controls.Add(next);
}

container.Controls.Add(nextTenRecords);
}

void nextTenRecords_Click(object sender, EventArgs e)
{
//throw new Exception("The method or operation is not implemented.");
intSlotNo++;

}

void prevTenRecords_Click(object sender, EventArgs e)
{
//throw new Exception("The method or operation is not implemented.");
intSlotNo--;
}


plz let me know how can i do that
AnswerRe: custom paging 'next/previous with numeric' Pin
Sabari MD12-Jul-09 19:53
Sabari MD12-Jul-09 19:53 
GeneralRe: custom paging 'next/previous with numeric' Pin
pupilstuff12-Jul-09 21:20
pupilstuff12-Jul-09 21:20 
Questionchange column value on linkbutton Pin
vikas shukla9-Jul-09 21:11
vikas shukla9-Jul-09 21:11 
QuestionHow to find out number of hits by a user on a specific page? Pin
Lijo Rajan9-Jul-09 21:01
Lijo Rajan9-Jul-09 21:01 
AnswerRe: How to find out number of hits by a user on a specific page? Pin
K03069-Jul-09 21:05
K03069-Jul-09 21:05 
AnswerRe: How to find out number of hits by a user on a specific page? Pin
Blue_Boy9-Jul-09 21:09
Blue_Boy9-Jul-09 21:09 
QuestionHello every one,i have a problem with Authentication. Pin
rinku soni 239-Jul-09 20:58
rinku soni 239-Jul-09 20:58 
AnswerRe: Hello every one,i have a problem with Authentication. Pin
K03069-Jul-09 21:02
K03069-Jul-09 21:02 
QuestionGridView DataBind, Adds an extra row to the gridview. Pin
AB77719-Jul-09 20:31
AB77719-Jul-09 20:31 
AnswerRe: GridView DataBind, Adds an extra row to the gridview. Pin
N a v a n e e t h9-Jul-09 20:33
N a v a n e e t h9-Jul-09 20:33 
GeneralRe: GridView DataBind, Adds an extra row to the gridview. Pin
AB77719-Jul-09 21:03
AB77719-Jul-09 21:03 
QuestionJavascript not firing in checkbox change Pin
meeram3959-Jul-09 19:51
meeram3959-Jul-09 19:51 
AnswerRe: Javascript not firing in checkbox change Pin
AB77719-Jul-09 20:33
AB77719-Jul-09 20:33 
AnswerRe: Javascript not firing in checkbox change Pin
N a v a n e e t h9-Jul-09 20:48
N a v a n e e t h9-Jul-09 20:48 
GeneralRe: Javascript not firing in checkbox change Pin
meeram3959-Jul-09 21:15
meeram3959-Jul-09 21:15 
GeneralRe: Javascript not firing in checkbox change Pin
N a v a n e e t h9-Jul-09 21:24
N a v a n e e t h9-Jul-09 21:24 
GeneralRe: Javascript not firing in checkbox change Pin
meeram3959-Jul-09 21:57
meeram3959-Jul-09 21:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.