How to Show Empty row in the grid view

Posted by rajrprk-12523 under ASP.NET on 11/7/2011 | Points: 10 | Views : 7260 | Status : [Member] | Replies : 5
I have a gridview that contain 25 records, in page size property i set to 10 records per page , then i will have 3 pages in the final page it displays only 5 rows, Here i want to show
10 rows. (First five records then next five as empty rows) Please post the help.
I think u got, If not please let me know




Responses

Posted by: Kishork80 on: 11/7/2011 [Member] Starter | Points: 25

Up
0
Down
If you are using class and entity then take list of empty object of the class and then bind that to gridview. This will bind the gridw with empty records.


kishor kumar

rajrprk-12523, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kishork80 on: 11/7/2011 [Member] Starter | Points: 25

Up
0
Down
Here is the sample code.

class Employee
{
public string Name { get; set; }
public string Age { get; set; }
public string Location { get; set; }
}
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Employee emp = null;

List<Employee> listEmployee = new List<Employee>();
for (int i = 0; i < 30; i++)
{
emp = new Employee();
//emp.Name = "Name :" + i.ToString();
//emp.Age = "Age :" + i.ToString();
//emp.Location = "Location :" + i.ToString();
listEmployee.Add(emp);
}

GridView1.DataSource = listEmployee;
GridView1.DataBind();


}

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.EditIndex = -1;
GridView1.SelectedIndex = -1;
}
}

kishor kumar

rajrprk-12523, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: rajrprk-12523 on: 11/8/2011 [Member] Starter | Points: 25

Up
0
Down
we can use this by while loop in the bind function.
dtable.Rows.Add(new object[ ] { "", "" });


rajrprk-12523, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 11/9/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
kishor how to add list item more than items using for loops

Mark as Answer if its helpful to you

rajrprk-12523, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: perfectchourasia-9163 on: 11/17/2011 [Member] Starter | Points: 25

Up
0
Down
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSqlDataSource"
autogeneratecolumns="true"
runat="server">

<emptydatarowstyle backcolor="LightBlue"
forecolor="Red"/>

<emptydatatemplate>

<asp:image id="NoDataImage"
imageurl="~/images/Image.jpg"
alternatetext="No Image"
runat="server"/>

No Data Found.

</emptydatatemplate>

</asp:gridview>

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

rajrprk-12523, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response