I have a custom GridView in asp.net Page. In PageLoad data will be bound to the grid.
protected void Page_Load(Object sender, EventArgs e)
{
InitDisplayMode(sender);
}
private void InitDisplayMode(Object sender)
{
pnlDetails.Visible = SafetyKeyId != -1;
if (!Page.IsPostBack)
{
BindValues();
}
// some other stuff
}
private void BindValues()
{
MyStrongTypedDataTable tbl = new BusinessObject.GetData();
dataGrid.DataSource = tbl;
dataGrid.DataBind();
}
Grid View Makrup
<asp:GridView ID="dataGrid" runat="server" AutoGenerateColumns="False" OnRowCreated="OnRowCreated"
AllowSorting="true" BorderWidth="0" CellPadding="2" CssClass="subitem w100p"
AllowPaging="true" PageSize="25" RowStyle-Wrap="false" HeaderStyle-Wrap="false"
OnPageIndexChanging="PageGrid" OnRowDataBound="dataGrid_RowDataBound" PagerSettings-Mode="Numeric"
PagerSettings-Position="Bottom" OnSorting="SortGrid" OnRowDeleting="RowDeleting">
<RowStyle CssClass="itemRowStyle"/>
<AlternatingRowStyle CssClass="alternatingItemRowStyle"/>
<HeaderStyle CssClass="headerRowStyle"/>
<Columns>
<asp:TemplateField ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle">
<ItemTemplate>
<asp:HyperLink ID="lnkDetail" runat="server" meta:resourcekey="lnkDetail" ImageUrl='<%# "~/App_Themes/" + Page.Theme + "/icons/16/icon_file.png" %>'
NavigateUrl="~/BrandMgmt/BrandMgmtPublicKey.aspx?"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle">
<ItemTemplate>
<asp:HyperLink ID="lnkEdit" runat="server" meta:resourcekey="lnkEdit" ImageUrl='<%# "~/App_Themes/" + Page.Theme + "/icons/16/icon_edit.png" %>'
NavigateUrl="~/BrandMgmt/BrandMgmtPublicKey.aspx?"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle">
<ItemTemplate>
<asp:ImageButton ID="cmdDelete" Width="16" Height="16" runat="server" ImageUrl='<%# "~/App_Themes/" + Page.Theme + "/icons/16/icon_delete.png" %>'
CommandName="Delete" CommandArgument='<%# Eval("SafetyKeyId") %>' OnCommand="OnDelete"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="KeyOwnerIdentifier" HeaderText="KeyOwnerIdentifier" meta:resourcekey="ColumnKeyOwnerIdentifier"
ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle" SortExpression="KeyOwnerIdentifier"/>
<asp:BoundField DataField="SafetyKeyName" HeaderText="SafetyKeyName" meta:resourcekey="ColumnSafetyKeyName"
ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle" SortExpression="SafetyKeyName"/>
<asp:BoundField DataField="SafetyKeyTypeId" HeaderText="SafetyKeyTypeId" meta:resourcekey="ColumnSafetyKeyTypeId"
ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle" SortExpression="SafetyKeyTypeId"/>
<asp:BoundField DataField="KeyIndex" HeaderText="KeyIndex" meta:resourcekey="ColumnKeyIndex"
ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle" SortExpression="KeyIndex"/>
<asp:BoundField DataField="FromDate" HeaderText="FromDate" meta:resourcekey="ColumnFromDate"
ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle" SortExpression="FromDate"/>
<asp:BoundField DataField="ToDate" HeaderText="ToDate" meta:resourcekey="ColumnToDate"
ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle" SortExpression="ToDate"/>
<asp:TemplateField ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle"
meta:resourcekey="ColumnPublicKey" SortExpression="PublicKey">
<ItemTemplate>
<div style="max-width: 200px; overflow-y: scroll;">
<asp:Label runat="server" Text='<%# Eval("PublicKey") %>'/>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Grid hat 3 ImageButtons for detail view, editing and deleting per row. DetaliView Button adds additional Table with data to the Page. Editing makes this Table editable. If the grid is sorted and any of those buttons is beeing clicked, Page loads and any sorting is lost.
How can I maintain the sort setting in PostBack after clicking any of those buttons?
Related
As written in the title, I am trying to get a textbox value from inside a DetailsView. However, the textbox value is not in the content of the Binded data in DetailsView, so when I try to get the text with the OnCommand method, I get an HttpContext error. Secondly, I can't reach the value using its ID, possibly due to it being in DetailsView. And finally, when I put the textbox and button outside of the DetailsView, I get the value, but the button and text shouldn't show up if there is no data to show in DetailsView.
This is my DetailsView code:
<asp:DetailsView ID="dvÜrün" runat="server" GridLines="None" CssClass="table table-borderless" AutoGenerateRows="false" OnCommand="dvÜrün_ItemCommand">
<Fields>
<asp:TemplateField Visible="false">
<ItemTemplate>
<%#Eval("ÜrünID") %> TL
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ÜrünAdı" HeaderText="Adı" />
<asp:BoundField DataField="ÜrünKategori" HeaderText="Kategori" />
<asp:BoundField DataField="ÜrünAçıklama" HeaderText="Açıklama" />
<asp:TemplateField HeaderText="Ücret">
<ItemTemplate>
<%#Eval("ÜrünÜcret") %> TL
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
Adet:
<asp:textbox ID="Adet" runat="server" CssClass="text-center" textmode="SingleLine" type="number" min="1" max="20" Text="1"/>
<asp:Button CssClass="pull-right btn btn-success" Text="Sepete Ekle" runat="server" OnClick="sepeteEkle_Click"/>
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
After posting this, I found the answer immediately. This is my cs code:
public void dvÜrün_ItemCommand(object sender, DetailsViewCommandEventArgs e)
{
if (e.CommandName == "ürünEkle")
{
string adet = ((TextBox)dvÜrün.FindControl("Adet")).Text;
}
}
This is the DetailsView code:
<asp:DetailsView ID="dvÜrün" runat="server" GridLines="None" CssClass="table table-borderless" AutoGenerateRows="false" OnItemCommand="dvÜrün_ItemCommand">
<Fields>
<asp:TemplateField Visible="false">
<ItemTemplate>
<%#Eval("ÜrünID") %> TL
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ÜrünAdı" HeaderText="Adı" />
<asp:BoundField DataField="ÜrünKategori" HeaderText="Kategori" />
<asp:BoundField DataField="ÜrünAçıklama" HeaderText="Açıklama" />
<asp:TemplateField HeaderText="Ücret">
<ItemTemplate>
<%#Eval("ÜrünÜcret") %> TL
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
Adet:
<asp:textbox id="Adet" runat="server" CssClass="text-center" textmode="SingleLine" type="number" min="1" max="20" Text="1"/>
<asp:Button CssClass="pull-right btn btn-success" Text="Sepete Ekle" runat="server" CommandName="ürünEkle"/>
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
I have a GridView, In one column I have LinkButton control. I want to disable click from client side for certain condition on this column. Means for some rows it will not be possible for User to call onclick event and for some rows it is possible.
I want to achieve this from client side using javascript.
Or When User clicks on link, It will notify the User that this action can't be completed for this row.
<asp:GridView Width="100%" ShowHeader="true" ViewStateMode="Enabled" GridLines="Both" CellPadding="10" CellSpacing="5" ID="GridViewMultiplePOSAssociationId" runat="server" AllowSorting="false" AutoGenerateColumns="false" OnRowCommand="RewardGridMultiD_RowCommand"
AllowPaging="true" PageSize="8" OnRowDataBound="grdViewCustomers_OnRowDataBound" PagerSettings-Position="Top" PagerSettings-Mode="NumericFirstLast" PagerSettings-FirstPageText="First" PagerSettings-LastPageText="Last" DataKeyNames="POS Id">
<RowStyle CssClass="table_inner_text" BackColor="WhiteSmoke" BorderColor="CornflowerBlue" Wrap="true" ForeColor="Black" Height="30px" />
<HeaderStyle CssClass="table_head_text" />
<Columns>
<asp:TemplateField ItemStyle-Width="80px">
<ItemTemplate>
<a href="JavaScript:divexpandcollapse('div<%# Eval(" POS Id ") %>');">
<img alt="Details" id="imgdiv<%# Eval("POS Id") %>" src="images/plus.png" />
</a>
<div id="div<%# Eval(" POS Id ") %>" style="display: none;">
<asp:GridView ID="grdViewOrdersOfCustomer" runat="server" AutoGenerateColumns="false" CssClass="ChildGrid">
<RowStyle CssClass="table_inner_text" BackColor="SkyBlue" BorderColor="Black" Wrap="true" ForeColor="White" Height="30px" />
<Columns>
<asp:BoundField ItemStyle-Width="150px" DataField="RULE FILE NAME" HeaderText="RULE FILE NAME" />
<asp:BoundField ItemStyle-Width="150px" DataField="RULE ID" HeaderText="RULE ID" />
<asp:BoundField ItemStyle-Width="150px" DataField="RULE TYPE ID" HeaderText="RULE TYPE ID" />
<asp:BoundField ItemStyle-Width="150px" DataField="START TIME" HeaderText="START TIME" />
<asp:BoundField ItemStyle-Width="150px" DataField="EXPIRY TIME" HeaderText="EXPIRY TIME" />
</Columns>
</asp:GridView>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="80px" ItemStyle-Width="80px" ItemStyle-HorizontalAlign="Center" HeaderText="Row Number">
<ItemTemplate>
<asp:Label ID="LabelRowNumberId" runat="server" Text='<%#Eval("Row Number") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="80px" ItemStyle-Width="80px" ItemStyle-HorizontalAlign="Center" HeaderText="POS Id">
<ItemTemplate>
<asp:Label ID="LabelPOSID" runat="server" Text='<%#Eval("POS Id") %>'></asp:Label>
<%-- <asp:LinkButton ID="LinkbtnPOSId" CommandArgument='<%#Eval("POS Id") %>' CommandName="ClickPOS" Text='<%#Eval("POS Id") %>' runat="server" CausesValidation="false"></asp:LinkButton>--%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="80px" ItemStyle-Width="250px" ItemStyle-HorizontalAlign="Center" HeaderText="Action">
<ItemTemplate>
<asp:LinkButton ID="HyperLinkAssociate" CommandArgument='<%#Eval("POS Id") %>' CommandName="Associate" Text="Associate" runat="server" OnClientClick="return OnClientClickAssociateRewardRuleFile(this);" CausesValidation="false"></asp:LinkButton>/
<asp:LinkButton ID="HyperLinkReplace" CommandArgument='<%#Eval("POS Id") %>' CommandName="Replace" Text="Replace" runat="server" OnClientClick="return OnClientClickReplaceRewardRuleFile(this);" CausesValidation="false"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="80px" ItemStyle-Width="250px" ItemStyle-HorizontalAlign="Center" HeaderText="Status">
<ItemTemplate>
<asp:Label runat="server" ID="LabelStatusPendingPOSId" Text='<%#Eval("Status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
In GridViewMultiplePOSAssociationId there is one column "Status" which has label LabelStatusPendingPOSId, LabelStatusPendingPOSId text is set Applied, Not Applied at the time of Binding. For Rows which has Status Applied, User should not be able to click on LinkButton Associate/Replace else He is allowed to click.
use this code OnRowDataBound for Your Grid
protected void grdViewCustomers_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.DataRow)
{
LinkButton LinkbtnPOSId=(LinkButton)e.Row.FindControl("LinkbtnPOSId");
Label LabelStatusPendingPOSId = (Label)e.Row.FindControl("LabelStatusPendingPOSId");
Boolean boolStatus = LabelStatusPendingPOSId.Text == "Applied" ? true : false;
//LinkbtnPOSId.Attributes.Add("onclick", "function CheckStatus('" + boolStatus.ToString() + "')");
LinkbtnPOSId.Enabled = boolStatus;
}
}
Try this..
You can loop through the Gridview and make the particular control disable...
I am writing the code in javascript pageload function...
function PageLoad(sender, args)
{
for (var i = 0; i <= RowCount; i++)
{
document.getElementById('Gridview1_HyperLinkAssociate_' + i.toString() + '').disabled = true;
}
}
Set RowCount as the number of rows of the Gridview...
I have a expand collapse nested grid view like below.
The childgrid (gvChild) column is a linkbutton column on the click of which I need to get the name of the city which was clicked. My rowcommand event to capture that on the child gridview is like this:
protected void gvChild_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "ShowDetails")
{
int index = Convert.ToInt32(e.CommandArgument);
GridView gridChild = (GridView)gvwParent.Rows[index].FindControl("gvChild");
foreach (GridViewRow row in gridChild .Rows)
{
string aCity= ((LinkButton)row.Cells[1].FindControl("lnkSelectedCity")).Text;
}
}
}
I understand the findcontrol line is def wrong, but how else would I do the findcontrol of the child grid to get the right link button that was clicked? Right now if I select "London", the Index value is 1 and the String "aCity" is taking it as "Utah". Will appreciate inputs on this. Thank you.
Code on my aspx page:
<asp:GridView ID="gvParent" runat="server"
AllowPaging="True" AutoGenerateColumns="False"
DataKeyNames="CountryID"
OnRowDataBound="gvParent_RowDataBound" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<a href="javaScript:divexpandcollapse('div<%# Eval("CountryID") %>');">
<img id='imgdiv<%# Eval("CountryID") %>' width="9px" border="0" src="expand_white.gif"
alt="" /></a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CountryDesc">
<ItemTemplate>
<asp:Label ID="lblEmpID" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "CountryDesc") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<tr>
<td colspan="100%">
<div id='div<%# Eval("CountryID") %>' style="display: none; position: relative; left: 15px; overflow: auto">
<asp:GridView ID="gvChild" runat="server" AutoGenerateColumns="False" PageSize="5"
Width="100%" Height="270px" ShowHeader="False" OnRowDataBound="gvChild_RowDataBound">
<Columns>
<asp:BoundField DataField="CityID" HeaderText="CityID">
<HeaderStyle CssClass="Invisible" />
<ItemStyle CssClass="Invisible" HorizontalAlign="Left" />
</asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkSelectedCity" runat="server" Text='<% # Eval("CityName") %>'
CommandName="ShowDetails" CommandArgument='<%# Container.DataItemIndex %>' ToolTip="Select x"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Assigned" HeaderText="Assigned">
<HeaderStyle CssClass="Invisible" />
<ItemStyle CssClass="Invisible" HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="CountryID" HeaderText="Assigned">
<HeaderStyle CssClass="Invisible" />
<ItemStyle CssClass="Invisible" HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="ClassID" HeaderText="ClassID">
<HeaderStyle CssClass="Invisible" />
<ItemStyle CssClass="Invisible" HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="UOM" HeaderText="UOM">
<HeaderStyle CssClass="Invisible" />
<ItemStyle CssClass="Invisible" HorizontalAlign="Left" />
</asp:BoundField>
</Columns>
</asp:GridView>
</div>
</td></tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I assume CityID is a unique key. If so, you can assign CityID to CommandArgument.
Then you can retrieve the CityID back from CommandArgument after post back.
<asp:GridView ID="gvChild" ... DataKeyNames="CityID">
<Columns>
...
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkSelectedCity"
...
CommandArgument='<%# Eval("CityID") %>'
ToolTip="Select x" />
</ItemTemplate>
</asp:TemplateField>
protected void gvChild_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "ShowDetails")
{
int cityId = Convert.ToInt32(e.CommandArgument);
}
}
I have a gridview populated with elements extracted from a table in the database. Each row contains 2 textboxes and 1 drop down list. The drop down list is filled when the page is loaded.
My issue is: when I edit the row, select another item from the drop down list and then click on update button, nothing changes. The drop down list still returns to its default value, neither the modiefied values are updated in the db (delete doesn't work etc). I can't understand the reason. Please help me.
My Gridview:
<asp:GridView ID="MyGridView" runat="server" AutoGenerateColumns="false" OnRowDataBound="GridView_OnRowDataBound" OnRowUpdating="GridView_OnRowUpdating"
DataKeyNames="id" DataSourceID="DataSource" ><AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowCancelButton="True" />
<asp:TemplateField HeaderText="currentCity" SortExpression="currentCity" ItemStyle- HorizontalAlign="Center" Visible="false">
<ItemTemplate>
<asp:Label runat="server" ID="lblcurrentCity" Text='<%# Bind("CodiceContrattoRisorsa") %>' Visible="false" ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="id" SortExpression="id" ItemStyle-HorizontalAlign="Center" >
<ItemTemplate>
<asp:TextBox runat="server" ID="txtId" Text='<%# Bind("id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="name" SortExpression="name" ItemStyle- HorizontalAlign="Center" >
<ItemTemplate>
<asp:TextBox runat="server" ID="txtName" Text='<%# Bind("name") %>'> </asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="city" SortExpression="city" ItemStyle- HorizontalAlign="Center">
<EditItemTemplate>
<asp:DropDownList ID="ddlCity" runat="server"></asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="ddlCity" runat="server" Enabled="false" >
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#EFF3FB" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
</asp:GridView>
<asp:EntityDataSource ID="DataSource"
runat="server" ContextTypeName="Context"
EntitySetName="users" EntityTypeFilter="user"
EnableDelete="True" EnableUpdate="True" />
Loading page....
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
MyGridView.DataBind();
}
protected void GridViewCausali_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// initialize ddl in gridview
DropDownList ddl = (DropDownList)e.Row.FindControl("ddlCity");
List<city> cities = new List<city>();
cities = GetFromDB();
ddl.DataSource = cities;
ddl.DataBind();
ddl.Items.FindByValue((e.Row.FindControl("lblcurrentCity") as
Label).Text).Selected = true;
}
}
protected void GridView_OnRowUpdating(object sender, GridViewUpdateEventArgs e)
{
DropDownList ddl = (DropDownList)MyGridView.Rows[e.RowIndex].FindControl("ddlCity");
string test = ddl.SelectedValue;
Label lbl = (Label)MyGridView.Rows[e.RowIndex].FindControl("lblcurrentCity");
lbl.Text = ddl.SelectedValue;
ddl.Items.FindByValue((MyGridView.Rows[e.RowIndex].FindControl("lblcurrentCity") as Label).Text).Selected = true;
}
I suggest you to add DefaultContainerName property, add stringconnection
<asp:EntityDataSource ID="DataSource" runat="server"
ConnectionString="name=..."
DefaultContainerName="..."
EntitySetName="users"
EnableDelete="True" EnableInsert="True" EnableUpdate="True"/>
protected void gvRequest_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
bm.DeleteBookRequest(Convert.ToInt32(e.CommandArgument));
GetBooks();
GetRequest();
}
}
<asp:GridView ID="gvBooks" runat="server" AutoGenerateColumns="false" DataKeyNames="Id"
BorderStyle="None" OnRowCommand="gvBooks_RowCommand" CssClass="gvBooks" CellPadding="5"
CellSpacing="7" ForeColor="Blue" OnRowDeleting="gvBooks_RowDeleting">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" />
<asp:BoundField DataField="Title" HeaderText="Title" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton CommandName="Select" CommandArgument='<%# Eval("Title") %>' runat="server"
ID="lb_Id">Select</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton CommandName="Delete" CommandArgument='<%# Eval("Title") %>' runat="server"
ID="lb_Title">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:GridView ID="gvReviews" runat="server" AutoGenerateColumns="false" OnRowCommand="gvReviews_RowCommand"
OnRowDeleting="gvReviews_RowDeleting" CellPadding="5" CellSpacing="7" ForeColor="Blue">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" />
<asp:BoundField DataField="Subject" HeaderText="Subject" />
<asp:BoundField DataField="Username" HeaderText="Username" />
<asp:BoundField DataField="Review" HeaderText="Review" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton CommandName="Delete" CommandArgument='<%# Eval("Id") %>' runat="server"
ID="lb_IdDel">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:GridView ID="gvRequest" runat="server" onrowcommand="gvRequest_RowCommand" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblName" runat="server" Text='<%# Eval("Title") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblUsername" runat="server" Text='<%# Eval("Username") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lbDelete" CommandName="Delete" CommandArgument='<%# Eval("id") %>' runat="server" Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
when I click on the delete linkbutton the output is a blank page.
The view source after the click button is clicked is as follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type>
<SCRIPT type=text/javascript src="http://www.google-analytics.com/ga.js"
async="true"></SCRIPT>
<SCRIPT type=text/javascript src="http://sg.perion.com/v1.1/js/gt.js"
async="true" onload="null"></SCRIPT>
</HEAD>
<BODY></BODY></HTML>
internal void DeleteBookRequest(int id)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "Delete from bookrequest where id=#id";
cmd.Parameters.Add("#id", SqlDbType.BigInt, 19, "id").Value = id;
cmd.Connection = connection;
connection.Open();
cmd.ExecuteNonQuery();
connection.Close();
}