gridview paging in popup - c#

I am Working in ASP.NET and c#.
I have gridview which i am binding on a button click,also am showing this gridview in popup.Now paging is not working in my gridview ,please help me out to solve this problem.
Aspx:
<asp:GridView ID="GV_Order" runat="server" AllowPaging="true" AutoGenerateColumns="false" DataKeyNames="ProductCode" EmptyDataText="There are no data records to display."
BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px"
CellPadding="4" CellSpacing="2"
HeaderStyle-BackColor="Black" HeaderStyle-ForeColor="#FFD700" PageSize="5" OnPageIndexChanging="GV_Orderpageindexchanging" o>
codebehind:
protected void btn_click(object sender,eventargs e)
{
GV_Order.DataSource = dataset;
GV_Order.DataBind();
}
protected void GV_Orderpageindexchanging(object sender, GridViewPageEventArgs e)
{
GV_Order.PageIndex = e.NewPageIndex;
GV_Order.DataBind();
}

asp.net DataPager control is not usefull,use Jquery Data Table for this.its realy nice working for all table.
add 'datatable' class to which table you want to use 'paging', 'searching','ordering'.. plugins ,

Related

Set an Attribute to the HeaderRow of the Radgrid [telerik] from Code Behind

I have a Radgrid like this in my ASPX page,
<telerik:RadGrid ID="rGVResults">
<MasterTableView AllowPaging="false" CellPadding="0" CellSpacing="0" AllowFilteringByColumn="true"
AllowSorting="true" AllowNaturalSort="false" Width="100%"
TableLayout="Auto" Frame="Void" GroupLoadMode="Client">
<Columns>
.
.
</Columns>
</MasterTableView>
</telerik:RadGrid>
Now I want to add an attribute to the header row of the radgrid from codebehind(aspx.cs) by doing this,
rGVResults.HeaderRow.Cells[0].Attributes["data-class"] = "expand";
Which works fine for an asp:gridview but not with the telerik radgrid.
What am I doing wrong?
Can someone suggest me an alternative?
Try this:
rGVResults.HeaderRow.Cells[0].Attributes.Add("data-class", "expand");
Or try this way
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem dataItem = e.Item as GridDataItem;
TableCell cell = dataItem["ColumnUniqueName"];
cell.Attributes["data-class"] = "expand";
}
}
You should try this:
rGVResults.HeaderStyle.CssClass = "expand";
The default value is System.String.Empty.

unable to update gridview values in .net

while updating gridview record . old values only getting updated. im using bound field. getting old value while im fetching data in variable.
<asp:GridView runat="server" ID="GvLeads" AutoGenerateColumns="false" AutoGenerateEditButton="true" AutoGenerateDeleteButton="true" OnRowDeleting="GvLeads_RowDeleting" OnRowEditing="GvLeads_RowEditing" OnRowCancelingEdit="GvLeads_RowCancelingEdit" EmptyDataText="No Records Found" OnRowUpdating="GvLeads_RowUpdating" OnRowDeleted="GvLeads_RowDeleted">
<Columns>
<asp:BoundField HeaderText="Id" DataField="LeadId" />
<asp:BoundField HeaderText="Company" DataField="Companyname" />
</Columns>
</GridView >
code behind
protected void GvLeads_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = GvLeads.Rows[e.RowIndex];
String str = ((TextBox)(row.Cells[1].Controls[0])).Text;
int Leadid = Convert.ToInt32(str);
string CompanyName = ((TextBox)(row.Cells[2].Controls[0])).Text;
}
This usually happens when you are populating grid at Page_Load as soon as RowUpdating event gets called before that Page_Load event get's called which populates the grid with initial values. How to Avoid? Use !IsPostBack for this purpose
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid(); // For e.g.
}
}

Display data from single column in multiple columns in GridView in ASP.NET

I am displaying data from my table (one column) in a grid, but the data is large (about 50 entries). Can I display the data in multiple columns/ rows so that it is easy for the user to read without scrolling down?
Here's my code.
ASPX:
<asp:GridView AlternatingRowStyle-BackColor="Wheat"
ID="GDV_1" runat="server"
EnableModelValidation="true"
AutoGenerateColumns="false"
OnSelectedIndexChanged="GDV_1_SelectedIndexChanged"
AutoGenerateSelectButton="false" DataKeyNames="SROID">
<Columns>
<asp:HyperLinkField DataTextField="SRONameinEnglish"
HeaderText="SRO Name"
DataNavigateUrlFields="SROID"
DataNavigateUrlFormatString="Webredirect2.aspx?SROID={0}" />
</Columns>
</asp:GridView>
ASPX.CS
protected void btn_submit_Click(object sender, EventArgs e)
{
FeesBLL p = new FeesBLL();
GDV_1.DataSource = p.table(txt_1.Text);
//GDV_1.Columns[1].Visible = true;
GDV_1.DataBind();
}
Kindly give you suggestion fr achieving the required result.

How to export selected data from my ASPx DevExpress gridview

I need to export to XLS the selected row of my DevExpress GridView.
When i try to export my grid, it creates an empty file. I think it is due to the callback that clear the data in my grid before exporting.
This is samples of my ASPx page.
The Load data button
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Styles/Images/load.png" onclick="ImageButton1_Click" />
The gridview
<dx:ASPxGridView ID="grid" ClientInstanceName="grid" runat="server" AutoGenerateColumns="False" KeyFieldName="car">
<Columns>
<dx:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="0" Caption="">
</dx:GridViewCommandColumn>
<dx:GridViewDataTextColumn Caption="Category" VisibleIndex="1" FieldName="category"
Name="category" GroupIndex="0" SortIndex="0" SortOrder="Ascending">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="Car" VisibleIndex="2" FieldName="car" Name="car">
</dx:GridViewDataTextColumn>
</Columns>
<SettingsPager PageSize="100">
</SettingsPager>
<Settings ShowFooter="True" />
<GroupSummary>
<dx:ASPxSummaryItem FieldName="car" SummaryType="Count" />
</GroupSummary>
</dx:ASPxGridView>
The GridExporter
<dx:ASPxGridViewExporter ID="gridExport" runat="server" GridViewID="grid" ExportedRowType="Selected" />
The create file button
<dx:ASPxButton ID="createFile" runat="server" Text="Create File" UseSubmitBehavior="False" OnClick="createFile_Click">
<Image Url="~/Styles/Images/save.png">
</Image>
</dx:ASPxButton>
Now the code behind.
When I click the load button, i create fake datas for my tests.
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
CreateFakeData();
}
I create my datas in a DataTable Object. And then i bind my dataTable with my grid.
grid.DataSource = fakes;
grid.DataBind();
Everything seem to works great but when i click the export button, nothing is exported.
protected void createFile_Click(object sender, EventArgs e)
{
gridExport.WriteXlsToResponse();
}
I followed the DevExpress tutoria to export selected rows in ASPl. But it seems that my page is refreshed so i loose the data binded with the grid before the export.
I had a similar situation when I was binding data to an ASPXGridView in the code behind. I was able to solve it by rebinding in the button click, before the export line.
protected void createFile_Click(object sender, EventArgs e)
{
grid.DataSource = fakes;
grid.DataBind();
gridExport.WriteXlsToResponse();
}
The problem was with the postback, as I expected, I needed a way to keep my gridView Datas somewhere and reload it after the postback.
I added the OnDataBinding attribute to my gridView
<dx:ASPxGridView ID="grid" ClientInstanceName="grid" runat="server"
AutoGenerateColumns="False" Width="100%" Caption="My car collection"
OnDataBinding="grid_DataBinding" KeyFieldName="car_model">
In the code behind, I coded the grid-DataBinding function so it restores the data using the data stocked in the session previously.
protected void grid_DataBinding(object sender, EventArgs e)
{
if (Session["gridData"] != null)
{
// Assign the data source in grid_DataBinding
grid.DataSource = Session["gridData"];
}
}
Don't forget to save the data in the session when desired. (I did it right after the search)
protected void searchBtn_Click(object sender, ImageClickEventArgs e)
{
datas = FindCars(input.Text);
grid.DataSource = datas;
grid.DataBind();
//Store data in the session
Session["gridData"] = this.datas;
}

GridView Paging is not working?

I have a grid in that i am using this code on page init
UpagedList = new PagedListAdapter<User>(UserListGridView);
UpagedList.MaxRows = ConfigurationService.DefaultPageSize;
UserListGridView.PageIndexChanged += delegate
{
Presenter.FillDataOnDropDown();
};
UserListGridView.Sorting += new GridViewSortEventHandler(UserListGridView_Sorting);
UserListGridView.Sorted += delegate {Presenter.SortChanged(); };
my grid code:
<asp:GridView CssClass="Greed" ID="UserListGridView" runat="server" DataSourceID="ListUserDataSource"
AutoGenerateColumns="false" EmptyDataText="No data found" DataKeyNames="Id" OnSorting="UserListGridView_Sorting" AllowSorting="True"
PageSize="25" AllowPaging="True" GridLines="None" EnableViewState="false">
<Columns></Columns>
</asp:GridView>
Paging is not working...? what else i need to do for paging.. when i am clicking on 2nd page page is not getting change but data is getting appended in grid
I think you missing the OnPageIndexChanging event in the gridview. Try adding this to your gridview OnPageIndexChanging="UserListGridViewIndexChanging"
and in the backend code
protected void UserListGridViewIndexChanging(object sender, GridViewPageEventArgs e)
{
UserListGridView.PageIndex = e.NewPageIndex;
Bind(); // you data bind code
}
hope this helps
protected void UserListGridViewIndexChanging(object sender, GridViewPageEventArgs e)
{
UserListGridView.PageIndex = e.NewPageIndex;
UserListGridView.DataBind();
Bind(); // you data bind code is here
}

Categories