ASP.NET - how to allow callback in gridview paging  ASP.NET - how to allow callback in gridview paging

Asked By ankush
14-Feb-11 02:05 AM
i have this grid......

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

Height="104px" Width="283px" CellPadding="6" CellSpacing="3" OnPageIndexChanging="GridView_Search_PageIndexChanging"

PageSize="5"

OnRowDataBound="GridView_Search_RowDataBound"

>

<Columns>

<asp:BoundField DataField="CompanyName" HeaderText="Company Name"

SortExpression="CompanyName" HeaderStyle-ForeColor=Blue >

<HeaderStyle ForeColor="Blue"></HeaderStyle>

</asp:BoundField>

<asp:BoundField DataField="State" HeaderText="State" SortExpression="State"

HeaderStyle-ForeColor=Blue>

<HeaderStyle ForeColor="Blue"></HeaderStyle>

</asp:BoundField>

<asp:BoundField DataField="City" HeaderText="City" SortExpression="City"

HeaderStyle-ForeColor=Blue>

<HeaderStyle ForeColor="Blue"></HeaderStyle>

</asp:BoundField>

<asp:BoundField DataField="Address" HeaderText="Address"

SortExpression="Address" HeaderStyle-ForeColor=Blue>

<HeaderStyle ForeColor="Blue"></HeaderStyle>

</asp:BoundField>

<asp:BoundField DataField="ZipCode" HeaderText="ZipCode"

SortExpression="ZipCode" HeaderStyle-ForeColor=Blue>

<HeaderStyle ForeColor="Blue"></HeaderStyle>

</asp:BoundField>

<asp:TemplateField HeaderText="Action">

<ItemTemplate>

<asp:ImageButton ID="ibtnEditCarrier" runat="server" ImageUrl="~/Images/Edit.gif"

ToolTip="Edit" />

<asp:ImageButton ID="ibtnDelCarrier" runat="server" ImageUrl="~/Images/Delete.gif"

ToolTip="Delete" />

</ItemTemplate>

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

</asp:TemplateField>

</Columns>

</asp:GridView>



i have to do callback in paging.i dont know how to do it.
pls sm1 help m out..
  div v replied to ankush
14-Feb-11 02:11 AM

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

Height="104px" Width="283px" CellPadding="6" CellSpacing="3" AllowPaging="True" OnPageIndexChanging="GridView_Search_PageIndexChanging"

PageSize="5"

OnRowDataBound="GridView_Search_RowDataBound"

>

<Columns>

<asp:BoundField DataField="CompanyName" HeaderText="Company Name"

SortExpression="CompanyName" HeaderStyle-ForeColor=Blue >

<HeaderStyle ForeColor="Blue"></HeaderStyle>

</asp:BoundField>

<asp:BoundField DataField="State" HeaderText="State" SortExpression="State"

HeaderStyle-ForeColor=Blue>

<HeaderStyle ForeColor="Blue"></HeaderStyle>

</asp:BoundField>

<asp:BoundField DataField="City" HeaderText="City" SortExpression="City"

HeaderStyle-ForeColor=Blue>

<HeaderStyle ForeColor="Blue"></HeaderStyle>

</asp:BoundField>

<asp:BoundField DataField="Address" HeaderText="Address"

SortExpression="Address" HeaderStyle-ForeColor=Blue>

<HeaderStyle ForeColor="Blue"></HeaderStyle>

</asp:BoundField>

<asp:BoundField DataField="ZipCode" HeaderText="ZipCode"

SortExpression="ZipCode" HeaderStyle-ForeColor=Blue>

<HeaderStyle ForeColor="Blue"></HeaderStyle>

</asp:BoundField>

<asp:TemplateField HeaderText="Action">

<ItemTemplate>

<asp:ImageButton ID="ibtnEditCarrier" runat="server" ImageUrl="~/Images/Edit.gif"

ToolTip="Edit" />

<asp:ImageButton ID="ibtnDelCarrier" runat="server" ImageUrl="~/Images/Delete.gif"

ToolTip="Delete" />

</ItemTemplate>

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

</asp:TemplateField>

</Columns>

</asp:GridView>

protected void GridView_Search_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
   gridView.PageIndex = e.NewPageIndex;
   gridView.DataBind();
}

  ankush replied to div v
14-Feb-11 02:25 AM
i have this code but the page postbacks..
if we implement thie method..GridView_Search_PageIndexChanging()
i want no page refresh..i have done callback thing in sorting..
in rowDataBoundEvent..
i checked if Row Type == dataControlRowType.Header

and then added attribute "onclick" to javascript function which in turn calls back the callBack function.
  div v replied to ankush
14-Feb-11 03:38 AM
hi,

ref this link http://weblogs.asp.net/aghausman/archive/2009/05/19/custom-paging-in-grid-view.aspx
http://www.dotnetspider.com/resources/39367-Gridview-Custom-Paging.aspx
this will help you...
  ankush replied to div v
15-Feb-11 04:18 AM
hey i found the solution without using custom paging..
see this..
just write this in

GridView_Search_RowCreated()



if (e.Row.RowType == DataControlRowType.Pager)

{

Table tb = new Table();

tb.BorderWidth = 0;

tb.Width = Unit.Percentage(15);

tb.Rows.Add(new TableRow());

for (int i = 0; i < GridView_Search.PageCount; i++)

{

TableCell tc = new TableCell();

tc.ForeColor = System.Drawing.Color.Blue;

tb.Rows[0].Cells.Add(tc);

System.Web.UI.WebControls.Label hlink = new System.Web.UI.WebControls.Label();

int paramIndex = i + 1;

hlink.Attributes.Add("onclick", "javascript:Paging('" + i + "','" + TextBox_CompanyName.ClientID + "','" + DropDownList_StateName.ClientID + "');return false;");

hlink.Text = "" + paramIndex;

tb.Rows[0].Cells[i].Controls.Add(hlink);

tb.Rows[0].Cells[i].HorizontalAlign = HorizontalAlign.Right;

}

e.Row.Cells[0].Controls.Clear();

e.Row.Cells[0].Controls.Add(tb);

}

and then in javascript fun u can handle the postback passing xml strings..
thanks for the reference..

Create New Account
help
PlaceHolder in GridView TemplateField Hi All, Can you please help me in solving the below problem. I have to place a placeholder in template field in Gridview so that i can make visible and non-visible the PlaceHolder based on certain conditions language = "C#" masterpagefile = "~ / MasterPages / Default.master" autoeventwireup = "true" codefile = "AddEmptyRowsUntilPageSizeMet.aspx.cs" inherits = "GridView_AddEmptyRowsUntilPageSizeMet" title = "GridView: Add Empty Rows Until Page Size Met" %> < asp:content id = "Content1" contentplaceholderid = "ContentPlaceHolder1" runat = "Server" > Select PageSize: < asp:dropdownlist id = "DropDownList1" runat = "server" autopostback = "true" onselectedindexchanged = "DropDownList1_SelectedIndexChanged" > < asp:listitem > 5< / asp:listitem > < asp:listitem 10< / asp:listitem > < asp:listitem > 15< / asp:listitem > < asp:listitem > 20< / asp:listitem > < / asp:dropdownlist > < asp:gridview id = "GridView1" runat = "server" allowpaging = "true" autogeneratecolumns = "false" pagesize = "5" style = "margin-top: 20px;" ondatabound onpageindexchanging = "GridView1_PageIndexChanging" > < columns > < asp:templatefield headertext = "Letter" > < itemtemplate > <%# Container.DataItem %> < / itemtemplate > < / asp:templatefield > < / columns > < / asp:gridview > < / asp:content > CODE-BEHIND using System; using System.Web.UI.WebControls; public partial class GridView_AddEmptyRowsUntilPageSizeMet i = GridView1.Rows.Count + 1; i < = GridView1.PageSize; i++) { GridViewRow row = new GridViewRow( 0, 0, DataControlRowType.DataRow, (i % 2 > 0) ? DataControlRowState.Normal : DataControlRowState.Alternate); foreach (DataControlField field in GridView1.Columns) { TableCell
edit and delete in gridview how to delete and edit data from database using gridview, give me code in c#.net 2.0 use this code <asp:GridView ID = "gdview" runat = "server" AutoGenerateColumns = "False" DataKeyNames = "CategoryID" OnRowCancelingEdit = "gdview_RowCancelingEdit" OnRowDeleting = "gdview_RowDeleting" OnRowEditing = "gdview_RowEditing" OnRowUpdating server" Text = "Delete" CommandName = "Delete"> < / asp:LinkButton> < / ItemTemplate> <ItemStyle Width = "100px" / > < / asp:TemplateField> < / Columns> < / asp:GridView> In code behind protected void Page_Load( object sender, EventArgs e) { if (!Page.IsPostBack) { bindgrid(); total sender, GridViewUpdateEventArgs e) { int catid = int .Parse(gdview.DataKeys[e.RowIndex].Value.ToString()); string strcatname = (( TextBox )gdview.Rows[e.RowIndex].Cells[0].Controls[0]).Text; SqlConnection conn = new SqlConnection ("Data Source DeleteCommand.ExecuteNonQuery(); conn.Close(); bindgrid(); } Hi, here is hte HTML and code for this. . . <asp:GridView ID = "GridView1" runat = "server" OnRowCommand = "GridView1_RowCommand" OnRowDataBound = "GridView1_RowDataBound" > <Columns> <asp:TemplateField> <ItemTemplate> <%# Eval( "PrimayKeyField" ) %> < / ItemTemplate asp:Button ID = "btnDelete" runat = "server" CommandName = "de" Text = "Delete" / > < / ItemTemplate> < / asp:TemplateField> < / Columns> < / asp:GridView> protected void GridView1_RowCommand( object sender, GridViewCommandEventArgs e) { / / for edut if (e.CommandName = = "ed" ) { / / get primary cmd.ExecuteNonQuery(); sqlCon.Close(); } } protected void GridView1_RowDataBound( object sender, GridViewRowEventArgs e) { if (e.Row.RowType = = DataControlRowType.DataRow) { / / get primarykey from first cell string strPrimaryKey = e.Row.Cells[0].Text; / / assign command
Gridview Edit, Update and Delete Hi as am new to ASP.NET i need some help in reviewing the code and find out the problem I have tried to create a gridview with insert, edit, update and delete . Also i have created a class file for database center" bgcolor = "#CC3300"> Email_address < / td> <td style = "width: 112px;" align = "center" bgcolor = "#CC3300"> Organisation <asp:DropDownList ID = "ddlorganisation" DataSourceID = "dsPopulateorganisation" AutoPostBack = "true" DataValueField = "Organisation" runat = "server" Width = "100px" Font-Size = "11px" AppendDataBoundItems = "true"> <asp:ListItem Text = "All" Value = "%"> < / asp:ListItem> < / asp:DropDownList> < / td> <td style = "width: 120px;" align = "center" bgcolor = "#CC3300"> Org_type <asp DropDownList ID = "ddlorgtype" DataSourceID = "dsPopulateorgtype" AutoPostBack = "true" DataValueField = "Org_type" runat = "server" Width = "100px" Font-Size = "11px" AppendDataBoundItems = "true"> <asp:ListItem Text = "All" Value = "%"> < / asp:ListItem> < / asp:DropDownList> < / td> <td style = "width: 115px;" align = "center" bgcolor = "#CC3300"> Client_PartnerId <asp:DropDownList ID = "ddlclientpartnerid" DataSourceID = "dsPopulateclientpartnerid" AutoPostBack = "true" DataValueField = "Client_PartnerId" runat = "server" Width = "100px" Font-Size = "11px AppendDataBoundItems = "true"> <asp:ListItem Text = "All" Value = "%"> < / asp:ListItem> < / asp:DropDownList> < / td> <td style = "width: 115px;" align = "center" bgcolor = "#CC3300"> Work_type <asp:DropDownList ID = "ddlworktype" DataSourceID
looks like below : protected void Gridview1_RowCreated( object sender, GridViewRowEventArgs e) { if (e.Row.RowType.Equals( DataControlRowType .DataRow)) { DataRowView objDRV = ( DataRowView )e.Row.DataItem; HyperLink objHlink = ( HyperLink )e.Row.FindControl( "hlContract" ); string into my aspx.cs: protected void gvContract_RowCreated( object sender, GridViewRowEventArgs e) { if (e.Row.RowType = = DataControlRowType .Header) { GridView header = ( GridView )sender; GridViewRow gvr = new GridViewRow (0, 0, DataControlRowType .Header, DataControlRowState .Insert); TableCell tCell = new TableCell (); tCell.Text = "Contract Management" ; tCell.ColumnSpan = 14; tCell HorizontalAlign .Left; tCell.CssClass = "trWithBorder" ; gvr.Cells.Add(tCell); / / Add the Merged TableCell to the GridView Header Table tbl = gvContract.Controls[0] as Table ; if (tbl ! = null ) { tbl.Rows.AddAt(0, gvr); } } if (e.Row.RowType.Equals( DataControlRowType .DataRow)) { DataRowView objDRV = ( DataRowView )e.Row.DataItem; HyperLink objHlink = ( HyperLink )e.Row.FindControl( "hlContract" ); string Can you please show your code of those page here where you are displaying 3 gridview ? Thks! This is the page where the 3 grid view are populated. Its called: http
gridview using dropdownlist hi anyone please send me the code to display paticular row of details in gridview by selecting the userid in dropdownlist and also allow to insert, update, edit, delete data in gridview after displaying it. mainly how to dropdownlist to database. thanks in advance For this you have to follow these steps- step1- Bind Data to DropDownList protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SqlConnection cn = new SqlConnection("con string DropDownList1.DataBind(); } Step2: Set AutoPostBack Property of DorpDownList to true Step3 : Implement SelectedIndexChange() Event of DropDownList protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { SqlConnection conn = new SqlConnection("con string "); SqlDataAdapter adapSel