I have a gridview nested inside a repeater, I want to change the header text of gridview columns on row databound or through
<HeaderTemplate>
<asp:Label runat="server" ID="lblMode" Text='<%# Eval("IsValidForPromoCode")%>'>
</asp:Label></HeaderTemplate>
whichever is convenient.
.aspx page
<asp:Repeater ID="repRequest" runat="server" OnItemDataBound="repRequest_ItemDataBound">
<ItemTemplate>
<table style="width: 100%; font-weight: bold;" cellpadding="5" cellspacing="0">
<tr>
<td colspan="12" align="right">
<a id="aSetPreference" runat="server" href="#">Attached Document(s)-</a>
<asp:Label ID="lblDocumentCount" CssClass="redFont" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td align="left" class="gray-bg" style="width: 8%;">
<b>Request#:</b>
</td>
<td style="width: 100px;">
<span class="detail-info-color">
<%# Eval("RequestNumber")%></span>
</td>
<td align="left" class="gray-bg" style="width: 5%;">
<asp:Label ID="lblreqDetID" runat="server" Visible="false" Text='<%# Bind("TravelDetailsID") %>'></asp:Label>
<b>Date:</b>
</td>
<td align="left" class="gray-bg" style="width: 5%;">
<b>Class:</b>
</td>
<td>
<span class="detail-info-color">
<%# Eval("Class")%></span>
</td>
</tr>
<tr>
<td colspan="12">
<asp:GridView ID="gvOption" CssClass="gridRow" runat="server" AutoGenerateColumns="False"
Width="100%" OnRowDataBound="gvOption_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="#">
<ItemTemplate>
<%#Container.DataItemIndex+1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Service Provider">
<ItemTemplate>
<asp:Label ID="txtNumber" runat="server" Width="80px" Text='<%# Bind("Number") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
<asp:Label runat="server" ID="lblMode" Text='<%# Eval("IsValidForPromoCode") %>'></asp:Label></HeaderTemplate>
<ItemTemplate>
<asp:Label ID="txtName" runat="server" Width="100px" Text='<%# Bind("Name") %>'></asp:Label>
<asp:Label ID="lblOptionID" Visible="false" runat="server" Width="100px" Text='<%# Bind("optionID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
Code behind
protected void gvOption_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
GridView gvOption = (GridView)sender;
if (e.Row.RowType == DataControlRowType.DataRow)
{
gvOption.Columns[1].HeaderText = "Last Name";
}
if (e.Row.RowType == DataControlRowType.Header)
{
gvOption.Columns[2].HeaderText = "Last Name";
}
}
catch (Exception ex)
{
throw ex;
}
}
Whichever way I am doing it's not effecting. Please suggest what I am missing.
Try this:-
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[1].Text = "Last Name";
}
Here, I have hard-coded the Cells value you need to change it accordingly.
Update:-
Find Control inside RowDataBound:-
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label txtNumber = (Label)e.Row.FindControl("txtNumber");
txtNumber.ForeColor = System.Drawing.Color.Red;
}
Related
how can i get selected value of dropdownlist on nested gridview row command.
I have a nested gridview in my page, inside of second gridview i want to use a drop down list for Driver. I am trying to get the selected value for that drop down list but unable to got it in gridview rowcommand. i try button click event also but i am unable to got it.
<asp:GridView ID="dtgNewTrips" runat="server" AllowPaging="true" AutoGenerateColumns="false" CssClass="table table-striped table-bordered table-hover" OnRowDataBound="dtgNewTrips_RowDataBound" DataKeyNames="Trips_ID">
<Columns>
<asp:TemplateField ItemStyle-Width="20px">
<ItemTemplate>
<a href="JavaScript:ViewDetails('div<%# Eval(" Trips_ID ") %>');">
<img alt="City" id="imgdiv<%# Eval("Trips_ID") %>" src="Images/Icons/plusicon.png" />
</a>
<div id="div<%# Eval(" Trips_ID ") %>" style="display: none;">
<asp:GridView ID="dtgViewDetails" runat="server" AutoGenerateColumns="false" DataKeyNames="Trips_ID" CssClass="ChildGrid" ShowHeader="false" OnRowDataBound="dtgViewDetails_RowDataBound" OnRowCommand="dtgViewDetails_RowCommand">
<Columns>
<asp:TemplateField ShowHeader="false">
<ItemTemplate>
<div>
<table style="width: 100%;">
<tr>
<td>Adults:
<asp:Label ID="lblTrip_ID" runat="server" Text='<%#Eval("Trips_ID") %>' Visible="false"></asp:Label>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("AdultsCount") %>'></asp:Label>
</td>
<td>Children:
<asp:Label ID="Label2" runat="server" Text='<%#Eval("ChildrensCount") %>'></asp:Label>
</td>
<td>Passenger Comments:
<asp:Label ID="Label4" runat="server" Text='<%#Eval("PassengerComments") %>'></asp:Label>
</td>
</tr>
<tr>
<td>Trip Stops:</td>
<td>
<asp:Label ID="Label3" runat="server" Text='<%#Eval("TripStops") %>'></asp:Label>
</td>
<td>TripStops Comments:
<asp:Label ID="Label5" runat="server" Text='<%#Eval("TripStopsComments") %>'></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlDriver" runat="server" DataTextField="DriverName" DataValueField="DriversInfo_ID" CssClass="form-control" AutoPostBack="false"></asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td>
<asp:Button ID="btnAssign" runat="server" Text="Assign To Driver" CssClass="btn btn-primary" CommandArgument='<%# ((GridViewRow)Container).RowIndex %>' CommandName="Assign" />
</td>
<td>
<asp:Button ID="btnAssignToAll" runat="server" OnClick="btnAssignToAll_Click" Text="Notify All Drivers" CssClass="btn btn-primary" />
<asp:Button ID="btnCancelTrip" runat="server" OnClick="btnCancelTrip_Click" Text="Cancel Trip" CssClass="btn btn-warning" />
</td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Trip No">
<ItemTemplate>
<asp:Label ID="lblTripRefID" runat="server" Text='<%#Eval("TripRefID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Customer Name">
<ItemTemplate>
<asp:Label ID="lblCompanyName" runat="server" Text='<%#Eval("CompanyName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Pickup Location">
<ItemTemplate>
<asp:Label ID="lblPickupLocation" runat="server" Text='<%#Eval("PickupLocation") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
C# Code
protected void dtgViewDetails_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Assign")
{
int rowIndex = Convert.ToInt32(e.CommandArgument);
GridView grid = (GridView)sender;
if (grid.ID == "dtgViewDetails")
{
Label lblTrip_ID = (Label)grid.Rows[rowIndex].FindControl("lblTrip_ID");
DropDownList ddlDriver = (DropDownList)grid.Rows[rowIndex].FindControl("ddlDriver");
}
}
}
But i get the by default of dropdownlist that zeroth index value.
please help me..
thanks in advance..
I recently switched a ComboBox in my repeater to a SuggestComboBox (found: here) because it is a contains search rather than a starts-with search. Previously, I was using NamingContainer of that ComboBox to find nearby elements. My new SuggestComboBox does not have this value but in my research on this problem, it looks like all children of a repeater should have this already?
"the NamingContainer property is available in code to any instance of that class or of a derived class." (found: here)
What am I missing?
Here's my repeater:
<asp:Repeater ID="repHW" runat="server" OnItemCommand="rep_ItemCommand">
<HeaderTemplate>
<table style="width:100%; padding-bottom:10px" id="HWtable">
<tr style="font-weight: bold"><td>Product</td><td>Part Number</td><td>Cost</td><td>Unit Price</td><td>Quantity</td><td>Price</td><td>Delete</td></tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<asp:HiddenField ID="Category" Value="Hardware" runat="server"/>
<td><asp:Label ID="Product" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Product.Name") %>' /></td> <!--TODO: make this clickable to edit -->
<td><asp:Label ID="PartNumber" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Product.PartNumber") %>' /></td>
<td><asp:Label ID="PartCost" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Product.Cost") %>' /></td>
<td><asp:Label ID="UnitPrice" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Product.Price") %>' /></td>
<td><asp:Label ID="Quantity" runat="server" Text='<%# Eval("Quantity") %>' /></td>
<td><asp:Label ID="Price" runat="server" Text='<%# Eval("Total") %>' /></td>
<td><asp:Button class="btn btn-danger" ID="DeleteHardware" runat="server" Text="Delete" CommandName="Delete" CommandArgument='<%# Container.ItemIndex %>'/></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<asp:HiddenField ID="AddCategory" Value="Hardware" runat="server"/>
<td><SuggestComboBox runat="server" ID="AddProduct" AutoCompleteMode="SuggestAppend" AutoPostBack="true" OnSelectedIndexChanged="ProductSelected" OnDataBinding="LoadHardwareProducts"/></td>
<td><asp:TextBox runat="server" ID="AddPartNumber" ClientIDMode="static"/></td>
<td><asp:TextBox runat="server" ID="AddPartCost" ClientIDMode="static"/></td>
<td><asp:TextBox runat="server" ID="AddUnitPrice" ClientIDMode="static"/></td>
<td><asp:TextBox runat="server" ID="AddQuantity" ClientIDMode="static"/></td>
<td><asp:Button class="btn btn-success" ID="AddHardware" runat="server" Text="Add" CommandName="Add" CommandArgument='<%# Container.ItemIndex %>' onClientClick="return EmptyFieldCheck('Hardware');"/></td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
and here's my function I am trying to access the other elements in:
protected void ProductSelected(Object source, EventArgs e)
{
SuggestComboBox temp = (SuggestComboBox)source;
List<Product> results = session.Query<Product>()
.Where(x => x.Name == temp.Text)
.ToList();
if(results.Count > 0)
{
Product p = results[0];
var repParent = temp.NamingContainer; //this broke
TextBox partNum = (TextBox)repParent.FindControl("AddPartNumber");
TextBox partCost = (TextBox)repParent.FindControl("AddPartCost");
TextBox unitPrice = (TextBox)repParent.FindControl("AddUnitPrice");
TextBox quantity = (TextBox)repParent.FindControl("AddQuantity");
partNum.Text = p.PartNumber;
partCost.Text = p.Cost.ToString();
unitPrice.Text = p.Price.ToString();
quantity.Text = p.DefaultQuantity.ToString();
}
}
I have a list of objects called dashboard which holds a list of Announcements with their AnnouncementId. My DataListAnnouncements.DataSource is equal to the dashboard but I can't figure out how to get the selectedItem equal to the item that I am selecting in the client side.
What Currently is happening is when I select an unread announcement, it displays the message with some css, but it does that to the wrong announcement at the moment.
protected void DataListAnnouncements_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "Select")
{
IList<DashBoardView> dashboard = new List<DashBoardView>();
dashboard = (IList<DataObjects.DashBoardView>)ListOfObjects;
UnreadAnnouncement unread = UnreadAnnouncements;
if (e.CommandArgument != null)
{
if (unread != null)
{
unread.WasRead = true;
UpdateUnreadAnnouncement(unread);
att = unread.AnnouncementId;
}
}
dashboard[e.Item.ItemIndex].WasRead = unread.WasRead;
DataListAnnouncements.DataSource = Session["dashboard"];
DataListAnnouncements.SelectedItem = dashboard[e.Item.ItemIndex]
(DataListAnnouncements.SelectedItem = att <---- Something Like this is what I would like to implement?)
Session["dashboard"] = dashboard;
bindDataList();
}
}
as you see now, I have it using the dashboard[e.Item.ItemIndex].WasRead = unread.WasRead line, but this proves to not work since the index is not always what I want. So I want to use an attribute. I looked around a bit but I am still fuzzy on how to implement it on the C# and asp side.
and this is my ASP.
<ItemTemplate>
<table width="880px">
<tr>
<td class="leftCol">
<asp:LinkButton Text='<%# Eval("title") %>' CssClass="bold" runat="server" CommandName="Select" CommandArgument='<%# Eval("UnreadAnnouncementId") %>' ID="titleLabel" /></span>
</td>
<td class="created">
<asp:Label Text='<%# DataBinder.Eval(Container.DataItem, "Effective", "{0:MM/dd/yyyy}") %>' CssClass="created" runat="server" ID="Label4" />
<br />
<asp:Label Text='<%# Eval("FirstName") %>' runat="server" ID="Label2" />
<asp:Label Text='<%# Eval("LastName") %>' runat="server" ID="Label3" />
</td>
</tr>
<tr>
<td class="one-long-line">
<asp:Label Text='<%# Eval("details") %>' CssClass="details" runat="server" ID="detailsLabel" />
</td>
</tr>
</table>
</ItemTemplate>
<SelectedItemTemplate>
<table width="880px" cellpadding="10px">
<tr>
<td class="leftCol">
<asp:Label Text='<%# Eval("title") %>' CssClass="bold" runat="server" ID="titleLabel" />
<asp:Label runat="server" ID="wasRead" Text='<%# Eval("wasRead") %>' Visible="false" Enabled="false" />
<td class="created">
<asp:Label Text='<%# DataBinder.Eval(Container.DataItem, "Effective", "{0:MM/dd/yyyy}") %>' CssClass="created" runat="server" ID="Label4" />
<br />
<asp:Label Text='<%# Eval("FirstName") %>' runat="server" ID="Label2" />
<asp:Label Text='<%# Eval("LastName") %>' runat="server" ID="Label3" />
</td>
</tr>
<tr>
<td class="deailsTD" colspan="2">
<asp:Label Text='<%# Eval("details") %>' CssClass="details" runat="server" ID="detailsLabel" />
</td>
</tr>
<tr>
</tr>
</table>
</SelectedItemTemplate>
I want to be able to click on a item in the datagrid, and it will expand that item and show me the details.
You have to use `SelectedIndex', not SelectedItem'. Source: How to: Allow Users to Select Items in DataList Web Server Controls.
It could be like this:
DataListAnnouncements.SelectedIndex = e.Item.ItemIndex;
From your code it is not clear what is the relation between dashboard and att. If there's any way to find the att in dashboard and find it's position, you can do like this:
DataListAnnouncements.SelectedIndex = attposition;
EDIT : There's an easy way to control background color of DataLists Items. We can parse each item in DataList's ItemBound and set BackColor like below:
protected void DataListAnnouncements_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem||
e.Item.ItemType == ListItemType.SelectedItem
)
{
// Here BackColor - Grey: WasRead; Yellow: Unread
var wasRead = ((DashBoardView)e.Item.DataItem).WasRead;
e.Item.BackColor = wasRead? System.Drawing.Color.Gray: System.Drawing.Color.Yellow;
}
}
You can even expand it more by splitting the if condition into two:
if (e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem){}
and
if ( e.Item.ItemType == ListItemType.SelectedItem){}
I use a jquery dialog and i want use CSS for the div area. I use a ListView with LinkButtons and I want a hover effect I try it with this but it don't work.
aspx: (div area)
<div id="dialog" title="Liste">
<asp:TextBox ID="txtBox" runat="server" ></asp:TextBox>
<asp:ImageButton ID="imageSearch" runat="server"
ImageUrl="~/Theme/Pictures/lupe.jpg" Height="24px" Width="25px"
onclick="imageSearch_Click" />
<asp:Button ID="btnEdit" runat="server" Text="Zu Vertreter hinzufügen"
onclick="btnEdit_Click" Width="246px"/>
<hr />
<asp:ListView runat="server" ID="myListView">
<LayoutTemplate>
<table id="UserTable" runat="server" border="0" width="100%" cellpadding="0" cellspacing="0">
<tr style="background-color:#ccdaeb" class="TableClass">
<th align="left" id="th4" runat="server"><asp:LinkButton ID="lnkNachname" runat="server" CssClass="MyLink">Name</asp:LinkButton> </th>
<th align="left" id="th6" runat="server"><asp:LinkButton ID="lnkAbteilung" CssClass="MyLink" runat="server">Abteilung</asp:LinkButton></th>
</tr>
<tr runat="server" id="ItemPlaceholder"></tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr class="TableClass">
<td align="left"><asp:LinkButton CssClass="MyLink" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="lblDisplayName" Text='<%# Eval("DisplayName") %>' runat="server" /></td>
<td align="left"><asp:LinkButton CssClass="MyLink" CommandName="abteilung" CommandArgument='<%# Container.DataItemIndex %>' ID="lblAbteilung" Text='<%# Eval("Abteilung") %>' runat="server" /></td>
</tr>
</ItemTemplate>
<EmptyDataTemplate>
<div><h4>Es wurden keine Einträge gefunden</h4></div>
</EmptyDataTemplate>
<AlternatingItemTemplate>
<tr class="TableClass">
<td align="left"><asp:LinkButton CssClass="MyLink" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="lblDisplayName" Text='<%# Eval("DisplayName") %>' runat="server" /></td>
<td align="left"><asp:LinkButton CssClass="MyLink" CommandName="abteilung" CommandArgument='<%# Container.DataItemIndex %>' ID="lblAbteilung" Text='<%# Eval("Abteilung") %>' runat="server" /></td>
</tr>
</AlternatingItemTemplate>
</asp:ListView>
</div>
My CSS file:
#UserTable
{
background-color:#ccdaeb;
}
.MyLink
{
color:Black;
text-decoration:none;
}
.MyLink:hover
{
text-decoration:underline;
}
#TableClass
{
background-color:#ccdaeb;
}
.TableClass:hover
{
background-color:#E5EDF5;
}
What I make wrong
#TableClass - it looks like mistake and should be .TableClass. Also .TableClass is applied to tr. Not sure why, but I've noticed that background-color does not work with TRs.
try change your css to
.TableClass td
{
background-color:#ccdaeb;
}
.TableClass:hover td
{
background-color:#E5EDF5;
}
Also, I see this code:id="UserTable" runat="server"
Because of runat=server id of that table will be changed, so css below will not work
#UserTable
{
background-color:#ccdaeb;
}
You may solve it like this:
<table id="UserTable" runat="server" class="UserTable" ...
and css:
.UserTable
{
background-color:#ccdaeb;
}
I had gridview which get data from database according to two event .The first from method ,the second when selected ddl.it worked well ,I made paging and when I go through paging pages I must click two click on number of page to go to this page also all pages get same data for firt page .So plaes any one help me.
<aspx>
<div class="div_open_CS m10 ad_mun_font">
<table width="560" border="0" align="center" cellpadding="2" cellspacing="0">
<tr>
<td class="pag_bor">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="Pag_toparow">
</td>
<td class="Pag_hedfont">
Dealers list
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="pag_bor">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="ad_mun_font_h" width="100">
Select City
</td>
<td>
<asp:SqlDataSource ID="SDSGetDealerArea" runat="server" ConnectionString="<%$ ConnectionStrings:ElarabyGroup %>"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT [AREA_ID], [AREA_ENG] FROM [DealerArea]">
</asp:SqlDataSource>
<%-- <asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>--%>
<asp:DropDownList CssClass="ad_mun_font_h" ID="DDlCity" runat="server" AutoPostBack="True"
DataSourceID="SDSGetDealerArea" DataTextField="AREA_ENG" DataValueField="AREA_ID"
OnDataBound="DDlCity_DataBound" OnSelectedIndexChanged="DDlCity_SelectedIndexChanged">
</asp:DropDownList>
<%-- </ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DDlCity" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>--%>
</td>
<td>
<asp:Label ID="LblResult" runat="server" Text="Result" Font-Bold="True" ForeColor="#006699"
Visible="false"></asp:Label>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top" class="tm10 rm10">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="None"
CellPadding="3" DataKeyNames="DEALER_ID,LOC_ID,CAT_ID,AREA_ID" CellSpacing="3"
GridLines="Horizontal" Width="510px" BorderWidth="1px" OnPageIndexChanging="GridView1_PageIndexChanging">
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<Columns>
<asp:TemplateField HeaderText="Name" SortExpression="NAME_ENG">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("NAME_ENG") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("NAME_ENG") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address" SortExpression="ADR_ENG">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("ADR_ENG") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("ADR_ENG") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Telephone" SortExpression="TEL_ENG">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("TEL_ENG") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("TEL_ENG") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Mobile" SortExpression="TEL_ARA">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("TEL_ARA") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("TEL_ARA") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Location" SortExpression="LOC_ENG">
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("LOC_ENG") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("LOC_ENG") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Category" SortExpression="CAT_NAME">
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("CAT_NAME") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("CAT_NAME") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Area" SortExpression="AREA_ENG">
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("AREA_ENG") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("AREA_ENG") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#DCDCDC" />
</asp:GridView>
<asp:Panel ID="pnlModal" runat="server" Style="display: none" CssClass="modalPopup">
Our Valued Customer You Are Not Registered Are You Want To Register?
<br />
<br />
<br />
<br />
<table id="LoginTL" runat="server" width="300" border="0" align="center" cellpadding="0"
cellspacing="2" visible="true" style="border-color: #666666">
<tr>
<td width="80px" class="bod_d_reg_txt_p lm7">
Username :
</td>
<td>
<label>
<asp:TextBox ID="TxtUser" runat="server" Width="125px"></asp:TextBox>
</label>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"
ControlToValidate="TxtUser" Display="Dynamic" SetFocusOnError="True">*</asp:RequiredFieldValidator>
</td>
<td>
<table width="110" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<label>
<asp:CheckBox ID="CBRemeber" runat="server" class="tx_s" OnCheckedChanged="CBRemeber_CheckedChanged" />
</label>
</td>
<td class="bod_d_reg_txt_w">
Remember me
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="80" class="bod_d_reg_txt_p lm7">
Password :
</td>
<td>
<label>
<asp:TextBox ID="TXTPassword" runat="server" TextMode="Password" Width="125px"></asp:TextBox>
</label>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="*"
ControlToValidate="TXTPassword" Display="Dynamic" SetFocusOnError="True">*</asp:RequiredFieldValidator>
</td>
<td>
<asp:ImageButton ID="IBLogin" runat="server" ImageUrl="images/home-d_login.jpg" OnClick="IBLogin_Click" />
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label8" runat="server" CssClass="ad_mun_font" Text="result" Visible="false"></asp:Label>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
Close
</td>
<td>
</td>
<td>
Register
</td>
</tr>
</table>
<br />
</asp:Panel>
<cc1:ModalPopupExtender TargetControlID="btnYes" ID="pnlModal_ModalPopupExtender"
runat="server" Enabled="True" BackgroundCssClass="modalBackground" PopupControlID="pnlModal"
CancelControlID="btnYes" DropShadow="true">
</cc1:ModalPopupExtender>
<asp:HiddenField ID="btnYes" runat="server" />
</td>
</tr>
</table>
</div>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridFunction();
}
}
private void BindGridFunction()
{
DataTable DT = new DataTable();
using (SqlConnection con = Connection.GetConnection())
{
SqlCommand Com = new SqlCommand();
if (DDlCity.SelectedIndex < 0)
{
Com = new SqlCommand("GetDealers", con);
Com.CommandType = CommandType.StoredProcedure;
SqlDataAdapter DA = new SqlDataAdapter(Com);
DA.Fill(DT);
GridView1.DataSource = DT;
GridView1.DataBind();
}
else
{
Com = new SqlCommand("GetDealersByArea", con);
Com.CommandType = CommandType.StoredProcedure;
Com.Parameters.Add(Parameter.NewNVarChar("#AREA_ENG", DDlCity.SelectedItem.Text));
SqlDataAdapter DA = new SqlDataAdapter(Com);
DA.Fill(DT);
GridView1.DataSource = DT;
GridView1.DataBind();
}
}
}
protected void DDlCity_SelectedIndexChanged(object sender, EventArgs e)
{
BindGridFunction();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
}
}
Try rebinding after GridView1.PageIndex = e.NewPageIndex; call GridView1.DataBind();
.
--EDIT--
DataSet and then DataBind(), try it like:
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
BindGridFunction();
}