this is my gridview in .NET c# with pagination
<asp:GridView ID="gvProducts" AutoGenerateColumns="False" EmptyDataText="ko" EnableViewState="true"
runat="server" DataKeyNames="ID" CssClass="mGrid" HorizontalAlign="Center"
OnRowDataBound="gvProducts_RowDataBound"
AllowPaging="True" PageSize="10"
OnPageIndexChanging="OnPageIndexChanging">
<AlternatingRowStyle CssClass="altrows" />
<Columns>
<asp:BoundField DataField="Nr" HeaderText="Nr." ReadOnly="true" HtmlEncode="false"
ItemStyle-CssClass="ddl_Class_new" ItemStyle-HorizontalAlign="Center" />
<asp:TemplateField HeaderText="Status" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:DropDownList ID="ddlstatus" runat="server" CssClass="pure-u-23-24"
AutoPostBack="true" OnSelectedIndexChanged="ddlstatus_SelectedIndexChanged">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="/aspnet/img/bot_back_1.gif"
CommandArgument="First" CommandName="Page" />
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="/aspnet/img/bot_back.gif"
CommandArgument="Prev" CommandName="Page" />
Page
<asp:DropDownList ID="ddlPages" runat="server" AutoPostBack="True" CssClass="ddl_Class"
OnSelectedIndexChanged="ddlPages_SelectedIndexChanged">
</asp:DropDownList>
of
<asp:Label ID="lblPageCount" runat="server"></asp:Label>
<asp:ImageButton ID="ImageButton3" runat="server" ImageUrl="/aspnet/img/bot_next.gif"
CommandArgument="Next" CommandName="Page" />
<asp:ImageButton ID="ImageButton4" runat="server" ImageUrl="/aspnet/img/bot_next_1.gif"
CommandArgument="Last" CommandName="Page" />
</PagerTemplate>
</asp:GridView>
on this gridview i have added this dropdownlist ddlstatus
<asp:TemplateField HeaderText="Status" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:DropDownList ID="ddlstatus" runat="server" CssClass="pure-u-23-24"
AutoPostBack="true" OnSelectedIndexChanged="ddlstatus_SelectedIndexChanged">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
when the dropdownlist ddlstatus is changed i need open new webpage on the browser
protected void ddlstatus_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ebb = (DropDownList)sender;
GridViewRow gvr = (GridViewRow)ebb.NamingContainer;
string dvalue = gvr.Cells[1].Text;
ClientScript.RegisterStartupScript(this.GetType(), "OpenWindow", "window.open('newpage.aspx?ID=" + dvalue.ToString() + "');", true);
}
but the new webpage on the browser is opened also if try change page on gridview
protected void ddlPages_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow gvrPager = gvProducts.BottomPagerRow;
DropDownList ddlPages = (DropDownList)gvrPager.Cells[0].FindControl("ddlPages");
gvProducts.PageIndex = ddlPages.SelectedIndex;
BindData();
}
protected void Paginate(object sender, CommandEventArgs e)
{
int intCurIndex = gvProducts.PageIndex;
switch (e.CommandArgument.ToString().ToLower())
{
case "First":
gvProducts.PageIndex = 0;
break;
case "Prev":
gvProducts.PageIndex = intCurIndex - 1;
break;
case "Next":
gvProducts.PageIndex = intCurIndex + 1;
break;
case "Last":
gvProducts.PageIndex = gvProducts.PageCount - 1;
break;
}
gvProducts.DataBind();
}
protected void gvProducts_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvProducts.PageIndex = e.NewPageIndex;
BindData();
}
protected void OnPageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvProducts.PageIndex = e.NewPageIndex;
BindData();
}
this is the the RowDataBound event
protected void gvProducts_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Pager)
{
DropDownList ddl = (DropDownList)(e.Row.FindControl("ddlpages"));
Label lblPageCount = (Label)e.Row.FindControl("lblPageCount");
if (lblPageCount != null)
lblPageCount.Text = gvProducts.PageCount.ToString();
for (int i = 1; i <= gvProducts.PageCount; i++)
{
ddl.Items.Add(i.ToString());
}
ddl.SelectedIndex = gvProducts.PageIndex;
if (gvProducts.PageIndex == 0)
{
((ImageButton)e.Row.FindControl("ImageButton1")).Visible = false;
((ImageButton)e.Row.FindControl("ImageButton2")).Visible = false;
}
if (gvProducts.PageIndex + 1 == gvProducts.PageCount)
{
((ImageButton)e.Row.FindControl("ImageButton3")).Visible = false;
((ImageButton)e.Row.FindControl("ImageButton4")).Visible = false;
}
}
}
i don't understand why this happens?
how to do resolve this?
thanks in advance for any help
I am trying to open my nested gridview for a single Parent Row and gets correctly open with one single record of the child row.
The paging of the rows is provided in the main gridview.
My problem is the page change, when I try change page I have this error :
GridView paging event gvProducts_PageIndexChanging not firing
How to do resolve this ?
My code below.
Thanks in advance for any help.
Code Markup
<asp:GridView ID="gvProducts" runat="server" AutoGenerateColumns="false" CssClass="Grid"
DataKeyNames="CustomerID" OnRowDataBound="gvProducts_RowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<img alt = "" style="cursor: pointer" src="images/plus.png" />
<asp:Panel ID="pnlOrders" runat="server" Style="display: none">
<asp:GridView ID="gvOrders" runat="server" AutoGenerateColumns="false" CssClass = "ChildGrid">
<Columns>
<asp:BoundField ItemStyle-Width="150px" DataField="OrderId" HeaderText="Order Id" />
<asp:BoundField ItemStyle-Width="150px" DataField="OrderDate" HeaderText="Date" />
</Columns>
</asp:GridView>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField ItemStyle-Width="150px" DataField="ContactName" HeaderText="Contact Name" />
<asp:BoundField ItemStyle-Width="150px" DataField="City" HeaderText="City" />
</Columns>
<PagerTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="/aspnet/img/bot_back_doppio.gif"
CommandArgument="First" CommandName="Page" />
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="/aspnet/img/bot_back.gif"
CommandArgument="Prev" CommandName="Page" />
Page
<asp:DropDownList ID="ddlPages" runat="server" AutoPostBack="True" CssClass="ddl_Class"
OnSelectedIndexChanged="ddlPages_SelectedIndexChanged">
</asp:DropDownList>
of
<asp:Label ID="lblPageCount" runat="server"></asp:Label>
<asp:ImageButton ID="ImageButton3" runat="server" ImageUrl="/aspnet/img/bot_next.gif"
CommandArgument="Next" CommandName="Page" />
<asp:ImageButton ID="ImageButton4" runat="server" ImageUrl="/aspnet/img/bot_next_doppio.gif"
CommandArgument="Last" CommandName="Page" />
</PagerTemplate>
</asp:GridView>
Code Behind
protected void gvProducts_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string customerId = gvProducts.DataKeys[e.Row.RowIndex].Value.ToString();
sql = #String.Format(" SELECT ... ");
GridView gvOrders = e.Row.FindControl("gvOrders") as GridView;
gvOrders.DataSource = GetData(sql);
gvOrders.DataBind();
}
if (e.Row.RowType == DataControlRowType.Pager)
{
DropDownList ddl = (DropDownList)(e.Row.FindControl("ddlpages"));
Label lblPageCount = (Label)e.Row.FindControl("lblPageCount");
if (lblPageCount != null)
lblPageCount.Text = gvProducts.PageCount.ToString();
for (int i = 1; i <= gvProducts.PageCount; i++)
{
ddl.Items.Add(i.ToString());
}
ddl.SelectedIndex = gvProducts.PageIndex;
if (gvProducts.PageIndex == 0)
{
((ImageButton)e.Row.FindControl("ImageButton1")).Visible = false;
((ImageButton)e.Row.FindControl("ImageButton2")).Visible = false;
}
if (gvProducts.PageIndex + 1 == gvProducts.PageCount)
{
((ImageButton)e.Row.FindControl("ImageButton3")).Visible = false;
((ImageButton)e.Row.FindControl("ImageButton4")).Visible = false;
}
}
}
protected void ddlPages_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow gvrPager = gvProducts.BottomPagerRow;
DropDownList ddlPages = (DropDownList)gvrPager.Cells[0].FindControl("ddlPages");
gvProducts.PageIndex = ddlPages.SelectedIndex;
BindData();
}
protected void Paginate(object sender, CommandEventArgs e)
{
int intCurIndex = gvProducts.PageIndex;
switch (e.CommandArgument.ToString().ToLower())
{
case "First":
gvProducts.PageIndex = 0;
break;
case "Prev":
gvProducts.PageIndex = intCurIndex - 1;
break;
case "Next":
gvProducts.PageIndex = intCurIndex + 1;
break;
case "Last":
gvProducts.PageIndex = gvProducts.PageCount - 1;
break;
}
gvProducts.DataBind();
}
protected void gvProducts_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvProducts.PageIndex = e.NewPageIndex;
BindData();
}
Please try this :
[Solution] The GridView 'GridView1' fired event PageIndexChanging which wasn't handled
I hope I was helpful.
I have a gridview in my project where like twitter you can see other peoples post but i want to allow users to change there posts and because of that near every post i putted an edit button. Now my problem is i cant lock the button if the user didnt post that tweet. can you show me how i can check if the users id (a given variable) matches the tweet user id (hidden field) i thought on using the for each loop but i cant succeed using it.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
ShowHeader="False" onrowcommand="GridView1_RowCommand"
onrowediting="GridView1_RowEditing" OnRowCancelingEdit="GridView1_Cancel"
onrowupdating="GridView1_RowUpdating"
onrowdeleting="GridView1_RowDeleting" >
<Columns>
<asp:TemplateField HeaderText="UserName">
<ItemTemplate>
<asp:Label ID="lbl_Username" runat="server" Text='<%#Eval("UserName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tweet">
<ItemTemplate>
<asp:Label ID="lbl_Tweet" runat="server" Text='<%#Eval("TweetText") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="Tbx_Tweet" runat="server" Text='<%#Eval("TweetText") %>' ></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Picture">
<ItemTemplate>
<asp:Image ID="Pic" runat="server" ImageUrl='<%#"~/UploadedImages/"+Eval("PicName") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Like">
<ItemTemplate>
<asp:Button ID="Button1" runat="server" Text="Like" CommandName="Like" CommandArgument='<%# Container.DataItemIndex %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ReTweet">
<ItemTemplate>
<asp:Button ID="Button2" runat="server" Text="ReTweet" CommandName="ReTweet" CommandArgument='<%# Container.DataItemIndex %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="TweetID" Visible="true">
<ItemTemplate>
<asp:Label ID="lbl_TweetID" runat="server" Text='<%#Eval("TweetID") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="UserID" Visible="true">
<ItemTemplate>
<asp:Label ID="lbl_UserID" runat="server" Text='<%#Eval("UserID") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate >
<asp:LinkButton ID="Edit" runat="server" Text="Edit" CommandName="Edit" />
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="Delete" runat="server" Text="Delete" CommandName="Delete" />
<asp:LinkButton ID="btn_Update" runat="server" Text="Update" CommandName="Update"/>
<asp:LinkButton ID="btn_Cancel" runat="server" Text="Cancel" CommandName="Cancel"/>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class Tweets : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
bool f = true;
if (!IsPostBack)
{
foreach (GridViewRow row in GridView1.Rows)
{
Label l = row.FindControl("UserID") as Label;
//Response.End();
//if (int.Parse(l.Text.ToString()) != 1)
//{
// Response.End();
// row.Cells[7].Visible = false;
//}
}
BindGridview();
//foreach (GridViewRow row in GridView1.Rows)
//{
// Label l = row.FindControl("UserID") as Label;
// Response.Write(l.Text);
// //if (int.Parse(l.Text.ToString()) != 1)
// //{
// // Response.End();
// // row.Cells[7].Visible = false;
// //}
//}
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int userId = 1;
if (e.CommandName == "Like")
{
int index = Convert.ToInt32(e.CommandArgument);
Label l = GridView1.Rows[index].FindControl("lbl_TweetID") as Label;
TweetHelper.Like(int.Parse(l.Text), userId);
}
if (e.CommandName == "ReTweet")
{
int index = Convert.ToInt32(e.CommandArgument);
Label l = GridView1.Rows[index].FindControl("lbl_TweetID") as Label;
TweetHelper.ReTweet(int.Parse(l.Text), userId);
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
}
protected void GridView1_Cancel(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
BindGridview();
}
public void BindGridview()
{
int userId = 1;
ServiceReference1.WebServiceSoapClient objWs = new ServiceReference1.WebServiceSoapClient();
DataSet ds = objWs.SelectTweets(userId, false);
DataTable dt = ds.Tables[0];
GridView1.DataSource = dt;
foreach (GridViewRow row in GridView1.Rows)
{
Label l = row.FindControl("UserID") as Label;
//if (int.Parse(l.Text.ToString()) != 1)
//{
// Response.End();
// // row.Cells[7].Visible = false;
//}
Response.Write(l.Text);
}
//int i = 0,x=0,y=0;
//DataTable dt1 = new DataTable();
//foreach (DataRow row in dt.Rows)
//{
// foreach (object obj in row.ItemArray)
// {
// dt1.Rows.Add(dt.Rows[x][4]);
// x++;
// }
//}
//foreach (DataRow row in dt1.Rows)
//{
// foreach (object obj in row.ItemArray)
// {
// if (obj.ToString() == userId.ToString())
// {
// GridView1.Rows[i].FindControl("Buttons").Visible = true;
// }
// else
// {
// GridView1.Rows[i].FindControl("Buttons").Visible = false;
// }
// i++;
// }
//}
GridView1.DataBind();
foreach (GridViewRow row in GridView1.Rows)
{
Label l = row.FindControl("UserID") as Label;
//if (int.Parse(l.Text.ToString()) != 1)
//{
// Response.End();
// // row.Cells[7].Visible = false;
//}
Response.Write(l.Text);
}
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
Label TweetID = GridView1.Rows[e.RowIndex].FindControl("lbl_TweetID") as Label;
TextBox TweetText = GridView1.Rows[e.RowIndex].FindControl("Tbx_Tweet") as TextBox;
TweetHelper.Updatetweet(int.Parse(TweetID.Text), TweetText.Text);
GridView1.EditIndex = -1;
BindGridview();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
}
}
You have more options to do it.
Create RowDataBound event handler and set up edit button Visibile/Enable property:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label userIdLbl = (Label)e.Row.FindControl("lbl_UserID");
LinkButton editBt = (LinkButton)e.Row.FindControl("Edit");
editBt.Visible = currentUserId == Convert.ToInt32(userIdLbl.Text);
}
}
Create a method in your code behind to check if the userId is currentUserId and add the attribute Visible/Enable to your edit button in gridview template:
Visible='<%# IsCurentUserId((int)Eval("UserID")) %>
Hi I want to have a DropDownList outside of my GridView that displays a list of page numbers. When the user clicks on a page number, the GridView should go to that page. I am able to populate the DropDownList, but it's not working with the GridView
Here is my GridView and DropDownList
<asp:DropDownList ID="ddlPageNumber" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlPaging_SelectedIndexChanged">
</asp:DropDownList> of
<%=GridView1.PageCount%>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" BorderStyle="Solid" GridLines="Both" HeaderStyle-BackColor="#990033" Width="1000px"
DataSourceID="EntityDataSource1" OnRowDataBound="GridView1_RowDataBound" OnDataBound="GridView1_DataBound">
<HeaderStyle ForeColor="White"></HeaderStyle>
<Columns>
<asp:BoundField DataField="intBatchID" HeaderText="Batch ID" ReadOnly="True"
SortExpression="intBatchID" />
<asp:BoundField DataField="vcharName" HeaderText="Name" ReadOnly="True"
SortExpression="vcharName" />
<asp:BoundField DataField="dtmScheduled" HeaderText="Date Scheduled"
ReadOnly="True" SortExpression="dtmScheduled" />
<asp:BoundField DataField="intBatchPriorityLevel"
HeaderText="Priority Level" ReadOnly="True"
SortExpression="intBatchPriorityLevel" />
</Columns>
<PagerSettings Mode="NumericFirstLast" Position="TopAndBottom" PageButtonCount="4" PreviousPageText="Previous" NextPageText="Next" FirstPageText="First" LastPageText="Last" />
<PagerStyle HorizontalAlign="Center" />
</asp:GridView>
Here's my code behind
protected void GridView1_DataBound(object sender, EventArgs e)
{
for (int cnt = 0; cnt < GridView1.PageCount; cnt++)
{
int curr = cnt + 1;
ListItem item = new ListItem(curr.ToString());
if (cnt == GridView1.PageIndex)
{
item.Selected = true;
}
ddlPageNumber.Items.Add(item);
}
}
protected void ddlPaging_SelectedIndexChanged(object sender, EventArgs e)
{
GridView1.PageIndex = ddlPageNumber.SelectedIndex;
}
After you update the PageIndex you need to rebind the grid, like this:
protected void ddlPaging_SelectedIndexChanged(object sender, EventArgs e)
{
GridView1.PageIndex = ddlPageNumber.SelectedIndex;
GridView1.DataBind();
}
UPDATE:
Since you are dynamically building the drop down list items for the page numbers, then you need to re-build them whenever a post back to the server happens or whenever the grid is rebound, like this:
private void BuildPageNumbers()
{
ddlPageNumber.Items.Clear();
for (int cnt = 0; cnt < GridView1.PageCount; cnt++)
{
int curr = cnt + 1;
ListItem item = new ListItem(curr.ToString());
if (cnt == GridView1.PageIndex)
{
item.Selected = true;
}
ddlPageNumber.Items.Add(item);
}
}
Now in your DataBound and Page_Load events, you can call this method, like this:
protected void Page_Load(object sender, EventArgs e)
{
BuildPageNumbers();
}
protected void GridView1_DataBound(object sender, EventArgs e)
{
BuildPageNumbers();
}
This question already has answers here:
I want to delete record from GridView.Before to this ask for confirmation like "Are you sure to delete?"
(4 answers)
Closed 9 years ago.
I need popup confirmation on button click deleting rows from asp.net gridview using c#.
Below is the code for button click for deleting rows from the gridview. I require popup confirmation before deleting.
Here is the code
protected void annDelete_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("chk_delete");
if (cb.Checked && cb != null)
{
{
int ID_No = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);
MySqlCommand com = new MySqlCommand();
com.CommandText = "Delete from announcement where id = '" + ID_No + "'";
com.Connection = con;
//con.Open();
com.ExecuteNonQuery();
con.Close();
GridView1.DataSource = null;
}
}
}
LoadIssueData();
}
this works for my delete button in gridview:
html:
<asp:GridView ID="gv" runat="server" AutoGenerateColumns="False"
AllowPaging="True" AllowSorting="True"
onpageindexchanging="gv_PageIndexChanging"
onsorting="gv_Sorting" GridLines="None" DataKeyNames="ID"
PageSize="20" onrowdeleting="gv_RowDeleting"
onrowdatabound="gv_RowDataBound" >
<PagerSettings FirstPageText="First" LastPageText="Last"
Mode="NumericFirstLast" NextPageText="Next" PageButtonCount="5"
PreviousPageText="Previous" />
<Columns>
<asp:BoundField DataField="SECURITIES_NAME" HeaderText="Securities Name"
SortExpression="SECURITIES" />
<asp:BoundField DataField="FIN_YEAR" HeaderText="Financial Year"
SortExpression="FIN_YEAR" />
<asp:BoundField DataField="RECORD_DATE" HeaderText="Record Date"
SortExpression="RECORD_DATE" />
<asp:BoundField DataField="AGM_DATE" HeaderText="AGM Date"
SortExpression="AGM_DATE" />
<asp:BoundField DataField="CA_SEQ_NO" HeaderText="CA SEQ NO"
SortExpression="CA_SEQ_NO" />
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<div class="actions">
<asp:LinkButton ID="lbView" runat="server" CausesValidation="True" CommandName="Select" Text="View"></asp:LinkButton>
<asp:LinkButton ID="lbEdit" runat="server" CausesValidation="True" CommandName="Edit" Text="Edit"></asp:LinkButton>
<asp:LinkButton ID="lbDelete" runat="server" OnClientClick="return confirm('Are you sure want to delete the Corporate Action?')" CausesValidation="False"
CommandName="Delete" Text="Delete"></asp:LinkButton>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle CssClass="pagination-flickr" BorderStyle="None" />
<HeaderStyle BorderStyle="None" />
<AlternatingRowStyle CssClass="altrow" />
</asp:GridView>
the codebehind cs:
protected void Page_Load(object sender, EventArgs e)
{
IsAuthenticated.CheckSession();
if (!IsPostBack)
{
if (Session["setFlash"] != null)
{
if (Session["setFlash"].ToString() == "1")
{
ltrMsg.Text = #"<div class='message-green'>Save Successfully</div>";
Session["setFlash"] = null;
}
else
{
ltrMsg.Text = #"<div class='message'>Not Save Successfully</div>";
Session["setFlash"] = null;
}
}
common.gv(#"Select SECURITIES_ID,BO_FNC_GET_SECURITIES_NAME(SECURITIES_ID) SECURITIES_NAME,
CA_SEQ_NO,FIN_YEAR,RECORD_DATE,AGM_DATE,SETUP_DATE,ID,ROWID From CA_MST", gv);
ViewState["sortingOrder"] = string.Empty;
DataBindGrid("", "");
}
}
protected void gv_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string wh = "ID='" + gv.DataKeys[e.RowIndex].Values[0].ToString() + "'";
DataProcess.Save("CA_MST", wh);
common.gv(#"Select SECURITIES_ID,BO_FNC_GET_SECURITIES_NAME(SECURITIES_ID) SECURITIES_NAME,
CA_SEQ_NO,FIN_YEAR,RECORD_DATE,AGM_DATE,SETUP_DATE,ID,ROWID FROM CA_MST", gv);
}
protected void gv_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gv.PageIndex = e.NewPageIndex;
common.gv(#"Select SECURITIES_ID,BO_FNC_GET_SECURITIES_NAME(SECURITIES_ID) SECURITIES_NAME,
CA_SEQ_NO,FIN_YEAR,RECORD_DATE,AGM_DATE,SETUP_DATE,ID,ROWID FROM CA_MST", gv);
}
private void DataBindGrid(string sortExpr, string sortOrder)
{
// GetDataTable returns a filled table
DataTable dt = DataProcess.getDataTable(#"Select SECURITIES_ID,BO_FNC_GET_SECURITIES_NAME(SECURITIES_ID) SECURITIES_NAME,
CA_SEQ_NO,FIN_YEAR,RECORD_DATE,AGM_DATE,SETUP_DATE,ID,ROWID FROM CA_MST");
// any check to validate dt
if (dt != null)
{
DataView dv = dt.DefaultView;
if (sortExpr != string.Empty)
dv.Sort = sortExpr + " " + sortOrder;
this.gv.DataSource = dv;
this.gv.DataBind();
}
else
{
this.gv.DataSource = null;
this.gv.DataBind();
}
}
protected void gv_Sorting(object sender, GridViewSortEventArgs e)
{
DataBindGrid(e.SortExpression, sortingOrder);
}
public string sortingOrder
{
get
{
if (ViewState["sortingOrder"].ToString() == "desc")
ViewState["sortingOrder"] = "asc";
else
ViewState["sortingOrder"] = "desc";
return ViewState["sortingOrder"].ToString();
}
set
{
ViewState["sortingOrder"] = value;
}
}
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lbv = (LinkButton)e.Row.FindControl("lbView");
lbv.PostBackUrl = "CaMstVw.aspx?rid=" + gv.DataKeys[e.Row.RowIndex].Values[0].ToString();
LinkButton lb = (LinkButton)e.Row.FindControl("lbEdit");
lb.PostBackUrl = "CaMstIns.aspx?rid=" + gv.DataKeys[e.Row.RowIndex].Values[0].ToString() ;
}
}
Assuming annDelete is an asp.net button control you may put following code to ask client confirmation:
HTML:
<asp:Button ID="annDelete" OnClientClick="if(!confirm('Confirm delete?')) return false;"></asp:Button>
return false will avoid server side hit.
Let's assume you have a <asp:Button> control.
Just add the OnClientClick event like:
<asp:Button id="btnDelete" OnClick="annDelete_Click"
OnClientClick="return confirm('Are you sure?');" />
the confirm javascript call will open a OK / Cancel alert and will return true if the user pressed OK of false otherwise, that you will return to the button.
the button will continue to invoke the __Post event only if you return true.
You can add OnClientClick attribute:
<asp:Button ID="annDelete" OnClientClick="return confirm('do you really want to delete?');" runat="server" Text="Button" OnClick="annDelete_Click" />
If user will choose ok, confirm function will return true and __doPostBack() function will be called, otherwise - not.