ASP, DropDownList grid view - c#

I'm new to ASP MVC. I want to load data from a database in DropDownList into a gridview. But DATA cannot load.
HTML CODE
<asp:BoundField DataField="id" HeaderText="Code">
<HeaderStyle Width="106px" HorizontalAlign="center" BorderColor="White" BorderWidth="1" />
<ItemStyle Width="102px" HorizontalAlign="center" BorderWidth="1px" />
</asp:BoundField>
<asp:BoundField DataField="name" HeaderText="Nom Cours">
<HeaderStyle Width="300px" HorizontalAlign="left" BorderColor="White" BorderWidth="1" />
<ItemStyle Width="300px" HorizontalAlign="left" BorderWidth="1px" />
</asp:BoundField>
<asp:templatefield HeaderText="Prix / Heure (HTG)">
<HeaderStyle Width="160px" HorizontalAlign="center" BorderColor="White" BorderWidth="1" />
<ItemStyle Width="160px" HorizontalAlign="center" BorderWidth="1px" />
<itemtemplate>
<asp:DropDownList ID="ddlprice" Width="160px" HorizontalAlign="center" runat="server">
</asp:DropDownList>
</itemtemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Sélectionner">
<HeaderStyle Width="300px" HorizontalAlign="center" BorderColor="White" BorderWidth="1" />
<ItemStyle Width="300px" HorizontalAlign="center" BorderWidth="1px" />
<itemtemplate>
<asp:checkbox ID="cbSelect" CssClass="gridCB" runat="server" HorizontalAlign="center"></asp:checkbox>
</itemtemplate>
</asp:templatefield>
</Columns>
<FooterStyle BackColor="Tan" Height="30px" HorizontalAlign="Center" />
<HeaderStyle BackColor="Navy" Font-Bold="True" Height="22px" HorizontalAlign="Left"
ForeColor="WhiteSmoke" BorderColor="Navy" VerticalAlign="Top" BorderWidth="2px" Width="910px" Font-Size="Small" />
<PagerSettings Mode="NumericFirstLast" />
<PagerStyle BackColor="SkyBlue" ForeColor="WhiteSmoke"
HorizontalAlign="Center" />
<RowStyle Height="5px" Font-Size="Smaller" />
<SelectedRowStyle BackColor="Aquamarine" ForeColor="GhostWhite" BorderColor="Silver"
BorderStyle="None" />
<SortedAscendingCellStyle BackColor="SkyBlue" />
<SortedAscendingHeaderStyle BackColor="#DAC09E" />
<SortedDescendingCellStyle BackColor="#E1DB9C" />
<SortedDescendingHeaderStyle BackColor="#C2A47B" />
</asp:GridView>
</div>
C# CODE
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ddlClassroom.SelectedValue = "-1";
BindDataGridClass();
BindDataGridCourse();
loadListPrice();
}
private void loadListPrice()
{
List<Course> listPrice = Course.getListCoursePriceOrdered();
ddlprice.DataValueField = "id";
ddlprice.DataTextField = "price";
ddlprice.DataSource = listPrice;
ddlprice.DataBind();
//ddlprice.Items.Insert(0, new DropDownListItem("--Selectionner--", "-1"));
ddlprice.SelectedValue = "0";
}

First add the OnRowDataBound event to the GridView
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound">
Then in code behind
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//check if the row is a datarow
if (e.Row.RowType == DataControlRowType.DataRow)
{
//find the dropdownlist in the row with findcontrol and cast it back to one
DropDownList ddlprice = e.Row.FindControl("ddlprice") as DropDownList;
//you now have access to all the dropdownlist properties
ddlprice.DataSource = Course.getListCoursePriceOrdered();
ddlprice.DataValueField = "id";
ddlprice.DataTextField = "price";
ddlprice.DataBind();
ddlprice.SelectedValue = "0";
}
}

Related

C# redirect to other page when gridview checkbox is ticked asp.net

i need you help guys,i have two pages and one with agridview with checkbox column, i want to redirect to the second page when the user tick the checkbox.
here is my code :
<asp:BoundField DataField="BC_Description" HeaderText="Description">
<HeaderStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="2px" HorizontalAlign="Center" />
<ItemStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="2px" Width="290px"
HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Update_Comments" HeaderText="Comments">
<HeaderStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="2px" HorizontalAlign="Center"
Width="100px" />
<ItemStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="2px" Width="350px"
HorizontalAlign="Left" />
</asp:BoundField>
<asp:TemplateField HeaderText="Changed">
<HeaderStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="2px" HorizontalAlign="Center" />
<ItemStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="2px" Width="150px"
HorizontalAlign="Center" />
<ItemTemplate>
<asp:CheckBox ID="chkApprove" runat="server" />
</ItemTemplate>
</asp:TemplateField>
if (!IsPostBack)
{
ChangedBy = getInfo.GetUserDetails(compileUserDI);
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("chkApprove");
if (cb.Checked)
{
Response.Redirect("CompileVariance.aspx");
}
}
The easiest way to do this is to make sure your checkbox triggers auto post back, and handle this event in the code behind:
<asp:CheckBox ID="chkApprove" runat="server" AutoPostBack="true" OnCheckedChanged="chkApprove_CheckedChanged" />
protected void chkApprove_CheckedChanged(object source, EventArgs e)
{
var checkbox = (CheckBox)source;
if (checkbox.Checked)
{
Response.Redirect("CompileVariance.aspx");
}
}

Gridview Command and Selected Row

I am trying to get the selected row data and transfer it to a label on the same page. However I cannot get the Gridview.SelectedRow to work with my CommandName. I have tried everything....
I get the error. Object reference not set to an instance of an object. on Label2.Text
Here is my Code:
protected void GridView1_RowCommand(Object sender, GridViewCommandEventArgs e)
{
// If multiple ButtonField column fields are used, use the
// CommandName property to determine which button was clicked.
if (e.CommandName == "Grab")
{
Label2.Text = GridView1.SelectedRow.Cells[2].Text;
Label3.Text = GridView1.SelectedRow.Cells[3].Text;
Label4.Text = GridView1.SelectedRow.Cells[4].Text;
Label5.Text = GridView1.SelectedRow.Cells[5].Text;
}
}
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" DataKeyNames="ID" DataSourceID="SqlDataSource1" ForeColor="Black" GridLines="Vertical" CssClass="td" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" Width="574px" onrowcommand="GridView1_RowCommand">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/images/edit.png" OnClick="ImageButton2_Click" />
<asp:ImageButton ID="ImageButton1" runat="server" CommandName="Select" ImageUrl="~/images/delete.png" onclientclick=" return confirm('Are you want to Delete this Vehicle?');" />
<asp:ImageButton ID="ImageButton3" runat="server" ImageUrl="~/images/refre.png" CommandName="Grab" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Year" HeaderText="Year" SortExpression="Year" />
<asp:BoundField DataField="Make" HeaderText="Make" SortExpression="Make" />
<asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" />
<asp:BoundField DataField="Submodel" HeaderText="Submodel" SortExpression="Submodel" />
<asp:BoundField DataField="ISENABLED" HeaderText="ISENABLED" SortExpression="ISENABLED" />
</Columns>
<FooterStyle BackColor="#CCCC99" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle BackColor="#F7F7DE" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FBFBF2" />
<SortedAscendingHeaderStyle BackColor="#848384" />
<SortedDescendingCellStyle BackColor="#EAEAD3" />
<SortedDescendingHeaderStyle BackColor="#575357" />
</asp:GridView>
Try something like this. Since you're trying to access the values in the command event and not in the OnSelectedIndexChanged event you need to get hold of the row triggering the command event first.
if (e.CommandName == "Grab")
{
GridViewRow row = (GridViewRow)((ImageButton)e.CommandSource).NamingContainer;
if (row != null)
{
Label2.Text = row.Cells[2].Text;
Label3.Text = row.Cells[3].Text;
Label4.Text = row.Cells[4].Text;
Label5.Text = row.Cells[5].Text;
}
}

Change background color of gridview row while processing

What I need to do is to highlight each row when it is processing to show the process progress, the gridview may contain almost one thousands of row. below is the code I have written but which doesn't work.
Please can someone help me.
<
asp:GridView ID="gdview1" runat="server" BackColor="White"
BorderColor="#DEDFDE" BorderStyle="Solid" BorderWidth="1px" CellPadding="4"
ForeColor="Black" GridLines="Vertical" Font-Names="Calibri"
Font-Size="Small" AutoGenerateColumns="False"
OnRowDataBound="gdview1_RowDataBound"
OnSelectedIndexChanged="gdview1_SelectedIndexChanged">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkBxHeader" OnCheckedChanged="chkSelect_CheckedChanged" AutoPostBack="true" runat="server" />
</HeaderTemplate>
<EditItemTemplate>
<asp:CheckBox ID="chkNUM" runat="server" />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkNUM" runat="server" DataField="ColNUM" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Row#">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ColNUM" HeaderText="Contract #" />
<asp:BoundField DataField="Col1" HeaderText="Suffix" />
<asp:BoundField DataField="Col2" HeaderText="First Name" />
<asp:BoundField DataField="Col3" HeaderText="Last Name" />
<asp:BoundField DataField="Col4" HeaderText="Street" />
<asp:BoundField DataField="Col5" HeaderText="City" />
<asp:BoundField DataField="Col6" HeaderText="Zip" />
</Columns>
<FooterStyle BackColor="#CCCC99" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle BackColor="#F7F7DE" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FBFBF2" />
<SortedAscendingHeaderStyle BackColor="#848384" />
<SortedDescendingCellStyle BackColor="#EAEAD3" />
<SortedDescendingHeaderStyle BackColor="#575357" />
</asp:GridView>
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void butChargeCreditCards_Click(object sender, EventArgs e)
{
DataTable tblContrts = (DataTable) Session["tblContrts"];
foreach (GridViewRow row in gdview1.Rows)
{
CheckBox chkbx = (CheckBox) row.FindControl("chkNUM");
if (chkbx != null && chkbx.Checked)
{
gdview1_SelectedIndexChanged(row,e);
string SS = chkbx.Text.ToString();
string strResults = method1;
}
}
}
protected void gdview1_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (GridViewRow row in gdview1.Rows)
{
if (row.RowIndex == gdview1.SelectedIndex)
{
row.BackColor = ColorTranslator.FromHtml("#A1DCF2");
}
else
{
row.BackColor = ColorTranslator.FromHtml("#FFFFFF");
}
}
}
}
}
Have you tried it by using the "OnRowDataBound" or "OnRowCreated" Event of the Grid and write the color-highliting in code behind?
Something like this?
http://www.java2s.com/Code/ASP/ADO.net-Database/UsingtheRowCreatedEventtoprogrammaticallychangethestyle.htm
But maybe you have a problem because the loading would be too fast to really notice?

Displaying CheckBox in Gridview DataBound based on varchar column

SQL Server table structure:
ChapName varchar(200)
Status varchar(1)
Requirement:
I want to display checkbox in an ASP.NET gridview from Visual Studio 2010
if the value of status column is T, let it be checked and unchecked otherwise.
but it shows only textbox.
I have tried <asp:templatefield> and <asp:itemtemplate> but it throws error if I try to bind this checkbox.
any sample code is required as I am beginner in this field.
The code I tried:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
CheckBox c = (CheckBox)GridView1.FindControl("ChkStatus");
TextBox TB = (TextBox)GridView1.FindControl("Status");
//Response.Write(TB.Text);
if (TB.Text == "T")
{
c.Checked = true;
}
else
{
c.Checked = false;
}
}
The error I got
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the
error and where it originated in the code.
Exception Details:
System.NullReferenceException: Object reference not set to an instance
of an object.
Aspx markup:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="Comp,QTypeCode" DataSourceID="SDS_QType_Edit"
BackColor="White" BorderColor="#DEDFDE" BorderStyle="None"
BorderWidth="1px"
CellPadding="4" ForeColor="Black" GridLines="Vertical"
AllowPaging="True" AllowSorting="True"
onselectedindexchanged="GridView1_SelectedIndexChanged"
onrowdatabound="GridView1_RowDataBound">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ShowEditButton="True" ShowSelectButton="True" />
<asp:BoundField DataField="QTypeCode" HeaderText="QTypeCode"
SortExpression="QTypeCode" InsertVisible="False"
ReadOnly="True" />
<asp:BoundField DataField="Descr" HeaderText="Descr" SortExpression="Descr" />
<asp:CheckBoxField DataField="AnsReq" HeaderText="AnsReq" ReadOnly="True"
SortExpression="AnsReq" />
<asp:CheckBoxField DataField="OptionPrint" HeaderText="OptionPrint"
ReadOnly="True" SortExpression="OptionPrint" />
<asp:BoundField DataField="Status" HeaderText="Status"
SortExpression="Status" />
<asp:BoundField DataField="TransDate" HeaderText="TransDate"
SortExpression="TransDate" />
<asp:BoundField DataField="UserName" HeaderText="UserName"
SortExpression="UserName" />
<asp:TemplateField HeaderText="Check Box" >
<ItemTemplate>
<asp:CheckBox ID ="ChkStatus" Text="text" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle Wrap="False" />
<EmptyDataRowStyle Wrap="False" />
<FooterStyle BackColor="#CCCC99" />
<HeaderStyle Wrap="False" BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle Wrap="False" BackColor="#F7F7DE" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White"
Wrap="False" />
<SortedAscendingCellStyle BackColor="#FBFBF2" />
<SortedAscendingHeaderStyle BackColor="#848384" />
<SortedDescendingCellStyle BackColor="#EAEAD3" />
<SortedDescendingHeaderStyle BackColor="#575357" />
</asp:GridView>
Assume you have grid defined as below on asmx
<asp:GridView ID="GridView1" runat="server"
onrowdatabound="GridView1_RowDataBound" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="ChapName" HeaderText="ChapName" />
<asp:TemplateField HeaderText="Status" Visible ="false">
<ItemTemplate>
<asp:Label ID="Status" runat="server" Text='<%# Bind("Status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Check Box" >
<ItemTemplate>
<asp:CheckBox ID ="ChkStatus" Text="text" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
on Row Data Bound event you can find controls as below
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
CheckBox c = e.Row.FindControl("ChkStatus") as CheckBox;
Label lbl = e.Row.FindControl("Status") as Label;
if (c!= null && lbl != null )
{
c.Checked = (lbl.Text == "T");
}
}

GridView allowPaging= true not showing page numbers 2 and 3. Shows 14567

i have a gridview that I need to have paged. When I allowPaging=true, It shows 145678910.... It won't show pages 2 and 3. If I try to change the Mode to NextPreviousFirstLast, It only shows 'Next' on the first page, and if I click that, it only shows 'First' and 'Last' on the second page. Here is the code:
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="Black" AutoGenerateColumns="False" BackColor="#CCCCCC"
BorderColor="#666666" OnRowDataBound = "HandleRowDataBound" BorderStyle="Solid" BorderWidth="1px" CellSpacing="2" Width ="942px"
Font-Names="Arial" Font-Size="8pt" ShowHeaderWhenEmpty="True" CSSClass="mytable" AllowPaging="true" OnPageIndexChanging="GridView1_PageIndexChanging"
PageSize="25">
<PagerSettings Mode="NextPreviousFirstLast" FirstPageText="First" PreviousPageText="Previous" NextPageText="Next" LastPageText="Last" />
<Columns>
<asp:TemplateField HeaderText="Select" ControlStyle-Width = "30px">
<ItemTemplate>
<asp:CheckBox runat="server" ID="DiscontinuedCheckBox" CssClass="SelectCheckBox" />
</ItemTemplate>
<ControlStyle Width="30px"></ControlStyle>
<ItemStyle Wrap="False" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Recall Qty" ItemStyle-Wrap="true" ItemStyle-Width="100px" >
<ItemTemplate >
<img id="star1" runat ="server" src="../Images/red_star.gif" alt="Red Star" class="RedStars"/>
<asp:TextBox runat ="server" ID="textBoxQty" Width = "50px" Text ="1" ReadOnly="false" />
</ItemTemplate>
<HeaderStyle Width = "100px" />
<ItemStyle Width="100px" />
<ItemStyle Wrap="False" Width="60px"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delivery Location" >
<ItemTemplate >
<div style="width:200px">
<div style ="float : left; ">
<asp:CheckBox runat="server" ID="packShipCB" Text ="Pack Ship or " CssClass="SendToShip" AutoPostBack="false" />
</div>
<asp:TextBox runat ="server" ID="deliveryLocationTB" CssClass="AllDelivery" ReadOnly ="false" Width="80px" />
</div>
</ItemTemplate>
<HeaderStyle Width = "200px" />
<ItemStyle Width="200px" />
<ItemStyle Width ="160px" />
</asp:TemplateField>
<%-- <asp:BoundField HeaderText="Data" />--%>
<asp:BoundField HeaderText="Request Number" DataField="requestNumber" ItemStyle-Width = "50px">
<HeaderStyle Wrap="True" Width="50px" />
<ItemStyle Wrap="True" Width="50px" />
</asp:BoundField>
<asp:BoundField HeaderText="Item Number" DataField="materialLineItemID" />
<asp:BoundField HeaderText="Program" DataField="programName" >
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField HeaderText="Program POC" DataField="programPOC" >
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField HeaderText="Material Number" DataField="materialNumber" ItemStyle-Width="100px">
<HeaderStyle Wrap="False" />
</asp:BoundField >
<asp:BoundField HeaderText="Qty in Storage" DataField="availableQty" ItemStyle-Width="100px">
<ItemStyle Width="100px" Wrap="False"></ItemStyle>
</asp:BoundField >
<asp:BoundField HeaderText="Description" DataField="Description" ItemStyle-Width="300px" >
<ItemStyle Width="300px" Wrap="False"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="Serialized" DataField="Serialized" ItemStyle-Width="100px">
<ItemStyle Width="100px"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="Serial Number" DataField="serialNumber" ItemStyle-Width="200px">
<ItemStyle Width="200px" Wrap="False"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="Shelf Life" DataField="shelfLIfe" DataFormatString="{0:d}" HtmlEncode="false" ItemStyle-Width="100px" >
<ItemStyle Width="100px"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="Cost Center" DataField="costCenter" ItemStyle-Width="200px">
<ItemStyle Width="200px" Wrap="False"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="Charge Number" DataField="chargeNumber" ItemStyle-Width="200px">
<ItemStyle Width="200px" Wrap="False"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="contractNumber" HeaderText="Contract Number" ItemStyle-Width="200px">
<HeaderStyle Wrap="False" />
<ItemStyle Width="200px" />
</asp:BoundField>
<asp:BoundField DataField="assetTagNumber" HeaderText="Asset Tag Number" ItemStyle-Width="200px">
<HeaderStyle Wrap="False" />
<ItemStyle Width="200px" />
</asp:BoundField>
<asp:BoundField HeaderText="Storage Duration" DataField="Duration" ItemStyle-Width="200px">
<ItemStyle Width="200px" Wrap="False"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="Handling Unit Number" DataField="handlingUnitNumber" ItemStyle-Width="100px">
<ItemStyle Width="100px" Wrap="False"></ItemStyle>
</asp:BoundField >
<asp:BoundField HeaderText="Storage Location" DataField="storageLocation" ItemStyle-Width="100px">
<ItemStyle Width="100px" Wrap="False"></ItemStyle>
</asp:BoundField >
<asp:BoundField HeaderText="Time in Storage" DataField="storageTime" ItemStyle-Width="200px">
<ItemStyle Width="200px" Wrap="False"></ItemStyle>
</asp:BoundField>
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="#999999" Font-Bold="True" ForeColor="#880C1B"
HorizontalAlign="Center" Font-Size="9pt" Wrap="true" BorderStyle="Solid" VerticalAlign="Middle"
BorderWidth="1px"/>
<PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
<RowStyle BackColor="White" HorizontalAlign="Center" CssClass="Unselected"
Wrap="false" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#808080" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>
and here is the code behind:
protected void Page_Load(object sender, EventArgs e)
{
siteID = int.Parse(Request.QueryString["s"].ToString());
FillDetails();
}
//Pulls data from database for items to be recalled based on site, and user rights and enables to functions of the controls
private void FillDetails()
{
DataSet materials = RequestDB2.GetStoredMaterialsView(siteID);
GridView1.DataSource = materials;
GridView1.DataBind();
if (GridView1.Rows.Count >= 9)
paneling.Style["height"] = "300px";
//if not items exit
if (materials == null || materials.Tables[0].Rows.Count == 0)
{
Error.InnerText = "You have no materials to be recalled from this site.";
}
else
{
//Adds thead and tbody tags
GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
protected void HandleRowDataBound(object sender, GridViewRowEventArgs e)
{
}
Here is what I see:
WHen I look at firebug, I see that pages 2 and 3 have display:none. ANy thoughts on why this might be happening?
You are not assigning data source in GridView1_PageIndexChanging. You need to assigned datasource before binding. You better try calling FillDetails()
Change
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
To
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
FillDetails();
}
Try using PagerSetting as..
<PagerSettings FirstPageText="First Page" LastPageText="Last Page"
Mode="NumericFirstLast" Position="TopAndBottom" />
protected void grdView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.DataSource = RequestDB2.GetStoredMaterialsView(siteID);
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}

Categories

Resources