I have table containing gridview inside an update panel "PanelSearch" whose display property is set to none.
When i first load the page i have added the table in a placeholder which is inside another updatepanel (main panel). I have a search button inside the "PanelSearch" and when user clicks search i am retrieving data from database and binding it to the gridview.
The gridview has linkbutton as templatefield and OnCommand event.
When i click the linkbutton no event gets fired but my page refreshes and table inside "PanelSearch' disappears.
I don't know why.Can anyone please help me?
My markup is as below;
<asp:UpdatePanel ID="PanelPatientSearch" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<table id="tablePatientSearch" clientidmode="Static" cellpadding="2" cellspacing="2" border="0"
style=" width:98%;display: table; margin-left: 10px;margin-right: 5px" runat="server" class="table">
<tr>
<th style="height:10px;width:100%"></th>
</tr>
<tr>
<td style="text-align: center">
<asp:Label ID="LabelSearchPatient" runat="server" CssClass="sectionHeaderForManagePages"
Text="Search Patient"></asp:Label>
</td>
</tr>
<tr>
<th style="height:10px;width:100%">
</th>
</tr>
<tr>
<td>
<table cellpadding="5" cellspacing="3" width="100%" >
<tr> <th colspan="4">
</th></tr>
<tr>
<th class="textCenterAlign" align="center" colspan="4"><asp:Label ID="labelSelectMessage" runat="server" Text="Search for Patient below or"></asp:Label>  
<asp:Button ID="buttonAddNewPatient" runat="server" CssClass="buttonLarge"
Text="Add Patient" onclick="buttonAddNewPatient_Click" CausesValidation="false" />
</th>
</tr>
<tr> <th colspan="4">
</th></tr>
<tr>
<td class="textRightAlign" width="25%">
<asp:Label ID="LabelPatientId" runat="server" Text="Patient ID" />
</td>
<td class="textLeftAlign" width="25%">
<asp:TextBox ID="textBoxID" runat="server" ClientIDMode="Static" CssClass="textBox" />
<asp:RequiredFieldValidator ID="RFVPatientID" runat="server" ControlToValidate="textBoxID"
CssClass="failureNotification" Display="None" ErrorMessage="Patient ID can not be blank"
SetFocusOnError="True" Width="0px"></asp:RequiredFieldValidator>
<cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender1" runat="server" CssClass="ajaxvalidatorPopup"
Enabled="True" TargetControlID="RFVPatientID">
</cc1:ValidatorCalloutExtender>
</td>
<td class="textRightAlign" width="25%">
<asp:Label ID="labelFirstName" runat="server" Text="First Name" />
</td>
<td class="textLeftAlign" width="25%">
<asp:TextBox ID="textBoxFirstName" runat="server" CssClass="textBox" />
</td>
</tr>
<tr>
<td class="textRightAlign" width="25%">
<asp:Label ID="labelLastName" runat="server" Text="Last Name" />
<br />
</td>
<td class="textLeftAlign" width="25%">
<asp:TextBox ID="textBoxLastName" runat="server" CssClass="textBox" />
<br />
</td>
<td class="textRightAlign" width="25%">
<asp:Label ID="labelDOB" runat="server" Text="Date of Birth" />
</td>
<td class="textLeftAlign" width="25%">
<asp:TextBox ID="textBoxDOB" runat="server" CssClass="textBox" />
<cc1:CalendarExtender ID="CalendarExtenderAppDate" runat="server" Enabled="True" Format="MM/dd/yyyy" TargetControlID="textBoxDOB">
</cc1:CalendarExtender>
</td>
</tr>
<tr>
<td class="textCenterAlign" colspan="4">
<br />
<asp:Button ID="buttonSearch" runat="server" CssClass="buttonLarge"
Text="Search" onclick="buttonSearch_Click" ClientIDMode="Static" CausesValidation="false" EnableViewState="false" />
<br />
<br />
</td>
</tr>
<tr>
<td colspan="4">
<br />
<asp:GridView ID="GridViewPatients1" runat="server" AutoGenerateColumns="False" CssClass="GridViewFullWidthCss"
EmptyDataText="No Patients are available" AllowPaging="True" OnRowCommand="GridViewPatients1_RowCommand"
AllowSorting="false" EnableViewState="true" ClientIDMode="Static" >
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:LinkButton ID="linkButtonSelect" runat="server" CommandName="Select" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"PatientID") %>' CausesValidation="false" OnCommand="SelectPatient" Text="Select" EnableViewState="true"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="PatientID" HeaderText="Patient ID" SortExpression="PatientID">
<ItemStyle Width="20%" />
</asp:BoundField>
<asp:BoundField DataField="first_name" HeaderText="First Name" SortExpression="FirstName">
<ItemStyle Width="20%" />
</asp:BoundField>
<asp:BoundField DataField="last_name" HeaderText="Last Name" SortExpression="LastName">
<ItemStyle Width="20%" />
</asp:BoundField>
<asp:BoundField DataField="birth_date" HeaderText="Date of Birth" SortExpression="DOB">
<ItemStyle Width="20%" />
</asp:BoundField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</td>
</tr>
</table>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="buttonSearch" EventName="click" />
</Triggers>
</asp:UpdatePanel>
And my code behind is like this
protected void SelectPatient(object sender, EventArgs e)
{
LinkButton lnkSelect = (LinkButton)sender;
Session["Selected_Patient_Id"] = lnkSelect.CommandArgument;
}
Generate RowCommand Event of GridView and use it like ..
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if(e.CommandName == "Select")
{
//write what you want to do
}
}
LinkButton click event doesn't fire because it is replace it's event on page load while you click on it.
You should use IsPostBack on Page_Load to avoid this. I think you are every time DataBind to GridView on page load.
So Ignore this and use code this way. It will be helpful for your problems.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
grid.DataSource = dsGrid;
grid.DataBind();
}
}
Related
I am trying to update the values of textboxes within an update panel from the rowcommand of a gridview, also within the update panel. The rowcommand is firing the update panel and running through the OnRowCommand code, however the values of the textboxes simply aren't being updated.
I am not getting any errors, and I have checked that I am not simply entering blank strings by tracing the value of the class I am supplying the values from.
Here is my code:
ASPX
<asp:Panel ID="pnlInspectorExpenses" CssClass="expenses" runat="server" Visible="false">
<asp:HiddenField ID="hdnInsExpID" runat="server" />
<asp:UpdatePanel ID="uPnlInspectorExpenses" runat="server">
<ContentTemplate>
<table>
<tr>
<td class="tableHead tableItem">IMO Number:</td>
<td class="tableField"><asp:Label ID="lblExpensesIMO" runat="server" /></td>
<td></td>
</tr>
<tr>
<td class="tableHead tableItem">Port of Vessel:</td>
<td class="tableField"><asp:Label ID="lblExensesPort" runat="server" /></td>
<td></td>
</tr>
<%--<tr>
<td class="tableHead tableItem">Report No.:</td>
<td class="tableField"><asp:Label ID="lblExpensesReportNo" runat="server" /></td>
<td></td>
</tr>--%>
<tr>
<td class="tableHead tableItem">Client Reference:</td>
<td class="tableField"><asp:Label ID="lblExpensesClientRef" runat="server" /></td>
<td></td>
</tr>
<tr>
<td class="tableHead tableItem">Vessel Type:</td>
<td class="tableField"><asp:Label ID="lblExpensesVesselType" runat="server" /></td>
<td></td>
</tr>
</table>
<table class="tableClass">
<tr>
<th align="left">Date</th>
<th align="left">Expense Description</th>
<th align="left">Type</th>
<th align="left">Currency</th>
<th align="right">Foreign Cost</th>
<th align="right">Exch. Rate</th>
<th align="right">GBP</th>
<th align="left">Receipt No</th>
<th colspan="2"></th>
</tr>
<tr>
<td colspan="10" class="zeroPadding">
<asp:GridView ID="grdInspectorExpenses" runat="server" CssClass="tableClass zeroMargin zeroBorder" DataKeyNames="ExpID" AutoGenerateColumns="false"
OnRowCommand="grdInspectorExpenses_RowCommand">
<Columns>
<asp:BoundField DataField="ExpDate" HeaderStyle-CssClass="invisible" ItemStyle-HorizontalAlign="Left" DataFormatString="{0:d}" ItemStyle-Width="90px" />
<asp:BoundField DataField="ExpDescription" HeaderStyle-CssClass="invisible" ItemStyle-HorizontalAlign="Left" ItemStyle-Width="220px" />
<asp:BoundField DataField="ExpType" HeaderStyle-CssClass="invisible" ItemStyle-HorizontalAlign="Left" ItemStyle-Width="100px" />
<asp:BoundField DataField="ExpCurrency" HeaderStyle-CssClass="invisible" ItemStyle-HorizontalAlign="Left" ItemStyle-Width="75px" />
<asp:BoundField DataField="ExpForeignCost" HeaderStyle-CssClass="invisible" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="75px" />
<asp:BoundField DataField="ExpExchangeRate" HeaderStyle-CssClass="invisible" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="80px" />
<asp:BoundField DataField="ExpLocalCost" HeaderStyle-CssClass="invisible" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="80px" />
<asp:BoundField DataField="ExpReceiptNo" HeaderStyle-CssClass="invisible" ItemStyle-HorizontalAlign="Left" ItemStyle-Width="80px" />
<asp:TemplateField HeaderStyle-CssClass="invisible" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="30px">
<ItemTemplate>
<asp:LinkButton ID="btnEditExpense" runat="server" Text="Edit" CommandName="Edit" CommandArgument="<%# Container.DataItemIndex %>" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-CssClass="invisible" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:LinkButton ID="btnDeleteExpense" runat="server" Text="Delete" OnClientClick="javascript: if (!confirm('Are you sure you want delete?')) return false;"
CommandName="Delete" CommandArgument="<%# Container.DataItemIndex %>" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
No expenses have yet been added
</EmptyDataTemplate>
</asp:GridView>
</td>
</tr>
<tr>
<td><asp:TextBox ID="txtInsExpDate" CssClass="datepicker" runat="server" Width="88px" style="padding: 5px 0px;" /></td>
<td><asp:TextBox ID="txtInsExpDesc" runat="server" Width="218px" style="padding: 5px 0;" /></td>
<td>
<asp:DropDownList ID="ddlExpenseType" runat="server" style="width:100px; padding: 4px 0;">
<asp:ListItem Text="General" Value="General" />
<asp:ListItem Text="Accommodation" Value="Accommodation" />
<asp:ListItem Text="Flight" Value="Flight" />
</asp:DropDownList>
</td>
<td><asp:TextBox ID="txtInsExpCurrency" runat="server" Width="68px" style="padding: 5px 0;" /></td>
<td><asp:TextBox ID="txtInsExpForVal" runat="server" Width="78px" style="text-align: right; padding: 5px 0;" /></td>
<td><asp:TextBox ID="txtInsExpExcRate" runat="server" Width="78px" style="text-align: right; padding: 5px 0;" /></td>
<td><asp:TextBox ID="txtInsExpLocVal" runat="server" Width="78px" style="text-align: right; padding: 5px 0;" /></td>
<td><asp:TextBox ID="txtInsExpRecNo" runat="server" Width="78px" style="padding: 5px 0;" /></td>
<td colspan="2" style="width:100px"></td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress5" runat="server" DynamicLayout="true">
<ProgressTemplate>
<div class="overlay" >
<img src="/Portals/_default/Skins/PMIT/Images/radarLoading.gif" />
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</asp:Panel>
ASPX.CS
protected void grdInspectorExpenses_RowCommand(object sender, GridViewCommandEventArgs e)
{
Trace.Warn("0");
if (e.CommandName == "Edit")
{
Trace.Warn("1");
int rowIndex = int.Parse(e.CommandArgument.ToString());
int ExpID = int.Parse(grdInspectorExpenses.DataKeys[rowIndex].Values[0].ToString());
hdnInsExpID.Value = ExpID.ToString();
List<ExpenseInfo> Expenses = IC.ExpenseSelect(ExpID);
ExpenseInfo Expense = Expenses[0];
txtInsExpDate.Text = Expense.ExpDate.ToString();
txtInsExpDesc.Text = Expense.ExpDescription;
ddlExpenseType.Items.FindByValue(Expense.ExpType).Selected = true;
txtInsExpCurrency.Text = Expense.ExpCurrency;
txtInsExpForVal.Text = Expense.ExpForeignCost.ToString();
txtInsExpExcRate.Text = Expense.ExpExchangeRate.ToString();
txtInsExpLocVal.Text = Expense.ExpLocalCost.ToString();
txtInsExpRecNo.Text = Expense.ExpReceiptNo;
Trace.Warn(Expense.ExpReceiptNo);
}
else if (e.CommandName == "Delete")
{
}
}
I figured this out in the end. It seems that if you name the CommandName "Edit", it calls the 'OnRowEditing' function, which was undefined. Therefore I just renamed the CommandName to "EditExpenses" instead. I did the same for the Delete command as well.
Please set the UpdatePanel's UpdateMode to Always to see if this makes a difference. For rules and conditions when an UpdatePanel content is updated, see here under Remarks: http://msdn.microsoft.com/en-us/library/system.web.ui.updatepanel.updatemode(v=vs.110).aspx
Here I had given "Showfooter"=true property but still it's not displaying
But while debug value(sumofamount) is assign to label.text
My GridView Code:
<asp:GridView ID="gvGrossDetails" runat="server" AllowPaging="true" AutoGenerateColumns="false"
CellPadding="0" CellSpacing="1" CssClass="grid_bg" GridLines="None" DataKeyNames="Code"
OnRowEditing="gvPayeeGross_RowEditing" OnRowDeleting="gvGrossDetails_RowDeleting"
OnRowUpdating="gvGrossDetails_RowUpdating" OnRowCancelingEdit="gvGrossDetails_RowCancelingEdit"
PagerStyle-Width="0px" PageSize="10" ShowFooter="true" Width="112%" Style="margin-top: 0px">
<PagerStyle CssClass="hide" />
<SelectedRowStyle CssClass="tble_hdr_not_sltd" />
<HeaderStyle CssClass="tble_hdr_not_sltd" />
<EmptyDataRowStyle CssClass="row_odd" HorizontalAlign="Center" />
<FooterStyle CssClass="hide" />
<RowStyle CssClass="row_even" />
<EmptyDataTemplate>
<table class="confirmation" cellpadding="0" cellspacing="0">
<tr>
<td>
<asp:Label Text="Records not found" ID="lblEmpty" runat="server"></asp:Label>
</td>
</tr>
</table>
</EmptyDataTemplate>
<AlternatingRowStyle CssClass="row_odd" />
<Columns>
<asp:TemplateField Visible="false">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblPayeeID1" runat="server" Text='<%#Bind("Code") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="0%" />
<HeaderStyle />
</asp:TemplateField>
<asp:TemplateField Visible="false">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblPayeeCode" runat="server" Text='<%#Bind("Code") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="0%" />
<HeaderStyle />
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="20%" HeaderStyle-HorizontalAlign="Left">
<HeaderTemplate>
Account head
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblGrossType" runat="server" Text='<%# Bind("Accounthead") %>' Wrap="true"></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="item_Style1" />
<EditItemTemplate>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="left" valign="middle" width="50%">
<asp:Label ID="txtGrossType" runat="server" Text='<%# Bind("Accounthead")%>'
CssClass="black_normal" Width="110px"></asp:Label>
</td>
</tr>
</table>
</EditItemTemplate>
<ItemStyle Width="20%" />
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="13%" HeaderStyle-HorizontalAlign="Left">
<HeaderTemplate>
Payee Amount
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblPresentedAmount" runat="server" Text=' <%# Eval("PayeeAmount")%>' Wrap="true"></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="item_Style1" />
<EditItemTemplate>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="left" valign="middle">
<asp:Label ID="txtPresentedAmount" runat="server" Text='<%# Bind("PayeeAmount")%>'
CssClass="black_normal" onblur="requiredCheck(this);" MaxLength="5" Width="110px"></asp:Label>
</td>
</tr>
</table>
</EditItemTemplate>
<FooterTemplate>
<asp:Label Text=Text='<%# GetTotalSalary() %>' ID="lbltotal" runat="server"></asp:Label>
</FooterTemplate>
<ItemStyle Width="13%" />
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="13%" HeaderStyle-HorizontalAlign="Left">
<HeaderTemplate>
Approved Amount
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblApproveAmount" runat="server" Text='<%# Eval("ApprovedAmount")%>'
Wrap="true"></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="item_Style1" />
<EditItemTemplate>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="left" valign="middle">
<asp:TextBox ID="txtApproveAmount" runat="server" Text='<%# Bind("ApprovedAmount")%>'
CssClass="black_normal" onblur="requiredCheck(this);" MaxLength="5" Width="110px"></asp:TextBox>
<ajaxToolkit:FilteredTextBoxExtender ID="fltrApprove" runat="server" FilterType="Custom"
FilterMode="InvalidChars" InvalidChars="'abcdefghijklmnopqrstuvwxyz#!#$%^&*%<> ,"
TargetControlID="txtApproveAmount">
</ajaxToolkit:FilteredTextBoxExtender>
</td>
</tr>
</table>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="approrve" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemStyle Width="13%" />
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="6%">
<HeaderTemplate>
<table width="100%" cellpadding="0" cellspacing="0" border="0" style="cursor: pointer;
cursor: hand;">
<tr>
<td align="right" style="display: none" valign="middle">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="left" width="70%">
<a>Delete</a>
</td>
<td style="width: 6px">
</td>
</tr>
</table>
</td>
<td align="right" valign="middle">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="left" width="70%">
<a>Delete</a>
</td>
<td style="width: 6px">
</td>
</tr>
</table>
</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table cellpadding="0" cellspacing="0" border="0" style="padding-left: 3px">
<tr>
<td align="right" height="19px" valign="middle">
<asp:Button ID="btnSEdit" CssClass="btnEdit" runat="server" CommandName="Edit" UseSubmitBehavior="false"
CausesValidation="false" />
</td>
<td align="right" height="19px" valign="middle">
<asp:Button ID="btnSDelete" CssClass="btnDelete" runat="server" CommandName="delete"
UseSubmitBehavior="false" CausesValidation="false" />
</td>
</tr>
</table>
</ItemTemplate>
<EditItemTemplate>
<table cellpadding="0" cellspacing="0">
<tr>
<td align="right" valign="middle" nowrap>
<asp:Button ID="btnSUpdate" CssClass="btnUpdate" runat="server" CommandName="Update"
UseSubmitBehavior="false" ValidationGroup="GSave" CausesValidation="false" />
<asp:Button ID="btnSCancel" CssClass="btnCancel" runat="server" CommandName="Cancel"
UseSubmitBehavior="false" CausesValidation="false" />
</td>
</tr>
</table>
</EditItemTemplate>
<ItemStyle Width="6%" />
</asp:TemplateField>
</Columns>
</asp:GridView>
sumof total
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Separator)
{
total += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "GrossAmount"));
}
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Separator)
{
total += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "ApprovedAmount"));
}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label lblamount = (Label)e.Row.FindControl("lblgrossamount");
lblamount.Text = total.ToString();
}
Here i had given "Showfooter"=true property but still it's not displaying
But while debug value(sumofamount) is assign to label.text
this line apply css for the gridview infooter:
<FooterStyle CssClass="hide" />
i think that this can hide the footr of gridview pls check this css...
In my project there are number of page inheriting the same masterpage and all are responding except 1 or 2 page, there is no change in code every thing is right.
I inserted breakpoint on button click button no effect.
How can i check the Problem.
Please help
Here is the code of my page
<%# Page Title="Product Stock" Language="C#" MasterPageFile="~/admin/AdminMaster.master" AutoEventWireup="true" CodeFile="ProductStock.aspx.cs" Inherits="admin_ProductStock" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
.auto-style3 {
width: 259px;
}
.auto-style4 {
width: 479px;
}
.auto-style5 {
height: 65px;
}
.auto-style6 {
width: 479px;
height: 65px;
}
.auto-style7 {
height: 74px;
}
.auto-style8 {
width: 479px;
height: 74px;
}
.auto-style9 {
width: 69px;
}
.auto-style10 {
height: 74px;
width: 68px;
}
.auto-style11 {
height: 65px;
width: 68px;
}
.auto-style12 {
width: 68px;
}
.auto-style13 {
width: 451px;
}
.auto-style14 {
width: 451px;
height: 74px;
}
.auto-style15 {
width: 451px;
height: 65px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" runat="server" contentplaceholderid="ContentPlaceHolder1">
<table style="width:100%;">
<tr>
<td>
<asp:Image ID="Image1" runat="server" Height="123px" ImageUrl="~/admin/images/insert.jpg" Width="158px" />
</td>
<td class="auto-style4">
<asp:Label ID="lblinsertion" runat="server" BackColor="#FFFF66" Font-Bold="True" Font-Italic="True" Font-Names="Euphemia" Font-Size="XX-Large" Font-Underline="True" ForeColor="#009900" Text="Insert Product Stock Information"></asp:Label>
</td>
<td class="auto-style12"> </td>
</tr>
<tr>
<td class="auto-style5">
<asp:Label ID="lblproductname" runat="server" Text="Product Name" Font-Bold="True" Font-Italic="True" Font-Size="Medium"></asp:Label>
</td>
<td class="auto-style6">
<asp:DropDownList ID="ddlprdctname" runat="server" Width="235px" ValidationGroup="vg1"></asp:DropDownList>
</td>
<td class="auto-style11">
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="ddlprdctname" ErrorMessage="Select Product Name" ValidationGroup="vg1"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblquantity" runat="server" Text="Quantity" Font-Bold="True" Font-Italic="True" Font-Size="Medium"></asp:Label>
</td>
<td class="auto-style4">
<asp:TextBox ID="txtquantity" runat="server" Width="235px" ValidationGroup="vg1"></asp:TextBox>
</td>
<td class="auto-style12">
<asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ControlToValidate="txtquantity" ErrorMessage="Enter Quantity" ValidationGroup="vg1"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblstocktype" runat="server" Text="Stock Type" Font-Bold="True" Font-Italic="True" Font-Size="Medium"></asp:Label>
</td>
<td class="auto-style4">
<asp:DropDownList ID="ddlstocktype" runat="server" Width="235px" Height="42px" ValidationGroup="vg1"></asp:DropDownList>
</td>
<td class="auto-style12">
<asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ControlToValidate="ddlstocktype" ErrorMessage="Please Enter Stock Type" ValidationGroup="vg1"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblstockdate" runat="server" Text="Stock Date" Font-Bold="True" Font-Italic="True" Font-Size="Medium"></asp:Label>
</td>
<td class="auto-style4">
<asp:TextBox ID="txtstockdate" runat="server" ValidationGroup="vg1" Height="55px" Width="235px"></asp:TextBox>
</td>
<td class="auto-style12">
<asp:Label ID="lbldateformat" runat="server" Text="dd/mm/yy"></asp:Label>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtstockdate" ErrorMessage="Please Enter Stock Date" ValidationGroup="vg1"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style3"></td>
<td class="auto-style4">
<asp:Button ID="btnInsert" runat="server" Text="Insert" Width="125px" ValidationGroup="vg1" OnClick="btnInsert_Click" />
</td>
<td>
<asp:Button ID="check" runat="server" Text="Lets Check" />
</td>
<td class="auto-style12"> </td>
</tr>
<tr>
<td colspan="3">
<asp:Label ID="lblmsg" runat="server" Font-Bold="True" Font-Italic="True" Font-Size="Medium"></asp:Label>
</td>
</tr>
</table>
</asp:Content>
<asp:Content ID="Content3" runat="server" contentplaceholderid="ContentPlaceHolder2">
<asp:Panel ID="ViewPanel" runat="server">
<table style="width:100%;">
<tr>
<td class="auto-style3">
<asp:Image ID="Image2" runat="server" Height="100px" ImageUrl="~/admin/images/view.jpg" Width="133px" />
</td>
<td>
<asp:Label ID="Label1" runat="server" BackColor="Yellow" Font-Bold="True" Font-Italic="True" Font-Names="Euphemia" Font-Size="XX-Large" Font-Underline="True" ForeColor="#009900" Text="View All Information"></asp:Label>
</td>
<td> </td>
</tr>
</table>
<asp:GridView ID="gridview" AutoGenerateColumns="false" runat="server" style="margin-left: 0px" AllowPaging="True" AllowSorting="True" CellPadding="3" Height="238px" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="Solid" BorderWidth="1px" CellSpacing="2" OnRowCommand="gridview_RowCommand" OnPageIndexChanging="gridview_PageIndexChanging">
<Columns>
<asp:BoundField HeaderText="Stock ID" DataField="StockID" />
<asp:BoundField HeaderText="Product Name" DataField="ProductID" />
<asp:BoundField HeaderText="Quantity" DataField="Quantity" />
<asp:BoundField HeaderText="Stock Type" DataField="StockType" />
<asp:BoundField HeaderText="Stock Date" DataField="StockDate" />
<asp:TemplateField HeaderText="Delete Record">
<ItemTemplate>
<asp:Button ID="delete" OnClientClick="return confirm('Are You Sure To Delete The Record?')" Text="Delete This Record" CommandName="del" CommandArgument='<%# Eval("StockID") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit Record">
<ItemTemplate>
<asp:Button ID="update" CommandName="upd" Text="Edit this Record" CommandArgument='<%# Eval("StockID") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FFF1D4" />
<SortedAscendingHeaderStyle BackColor="#B95C30" />
<SortedDescendingCellStyle BackColor="#F1E5CE" />
<SortedDescendingHeaderStyle BackColor="#93451F" />
</asp:GridView>
<asp:Label ID="lblMessage" runat="server" Text=""></asp:Label>
</asp:Panel>
<br />
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolder3" Runat="Server">
<asp:Label ID="lblupdate" runat="server" Text="Select the record to be updated" Font-Names="Segoe Print" Font-Size=20></asp:Label>
<asp:Panel ID="UpdatePanel" runat="server">
<table style="width:100%;">
<tr>
<td>
<asp:Image ID="Image3" runat="server" Height="123px" ImageUrl="~/admin/images/insert.jpg" Width="158px" />
</td>
<td >
<asp:Label ID="lblupdupdation" runat="server" BackColor="#FFFF66" Font-Bold="True" Font-Italic="True" Font-Names="Euphemia" Font-Size="XX-Large" Font-Underline="True" ForeColor="#009900" Text="Update Product Stock Information"></asp:Label>
</td>
<td > </td>
</tr>
<tr>
<td>
<asp:Label ID="lblupdstockid" runat="server" Text="Quantity" Font-Bold="True" Font-Italic="True" Font-Size="Medium"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtupdstockid" runat="server" ReadOnly="true" Width="235px"></asp:TextBox>
</td>
</tr>
<tr>
<td >
<asp:Label ID="lblupdproductname" runat="server" Text="Product Name" Font-Bold="True" Font-Italic="True" Font-Size="Medium"></asp:Label>
</td>
<td >
<asp:DropDownList ID="ddlupdprdctname" runat="server" Width="235px"></asp:DropDownList>
</td>
<td >
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="ddlupdprdctname" ErrorMessage="Enter Product Name"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblupdquantity" runat="server" Text="Quantity" Font-Bold="True" Font-Italic="True" Font-Size="Medium"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtupdquantity" runat="server" Width="235px"></asp:TextBox>
</td>
<td >
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtupdquantity" ErrorMessage="Enter Quantity"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblupdstocktype" runat="server" Text="Stock Type" Font-Bold="True" Font-Italic="True" Font-Size="Medium"></asp:Label>
</td>
<td >
<asp:DropDownList ID="ddlupdstocktype" runat="server" Width="235px"></asp:DropDownList>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="ddlupdstocktype" ErrorMessage="Please Enter Stock Type"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblupdstockdate" runat="server" Text="Stock Date" Font-Bold="True" Font-Italic="True" Font-Size="Medium"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtupdstockdate" runat="server" ValidationGroup="vg1" Height="16px" Width="235px"></asp:TextBox>
</td>
<td >
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="txtupdstockdate" ErrorMessage="Please Enter Stock Date" ValidationGroup="vg1"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td></td>
<td >
<asp:Button ID="btnUpdate" runat="server" Text="Update" Width="125px" ValidationGroup="vg1" OnClick="btnUpdate_Click" />
</td>
<td > </td>
</tr>
<tr>
<td colspan="3">
<asp:Label ID="lblupdmsg" runat="server" Font-Bold="True" Font-Italic="True" Font-Size="Medium"></asp:Label>
</td>
</tr>
</table>
</asp:Panel>
</asp:Content>
My Client side code for button
protected void btnInsert_Click(object sender, EventArgs e)
{
try
{
int productID, quantity;
string stockType;
DateTime stockDate;
productID = int.Parse(ddlprdctname.SelectedValue);
quantity = int.Parse(txtquantity.Text.Trim());
stockType = ddlstocktype.SelectedValue.ToString().Trim();
stockDate = DateTime.Parse(txtstockdate.Text.Trim());
ProductStock prdctstock = new ProductStock();
prdctstock.ProductID = productID;
prdctstock.Quantity = quantity;
prdctstock.StockType = stockType;
prdctstock.StockDate = stockDate;
if (new InsertAction().InsertData(prdctstock))
{
lblmsg.Text = "Inserted Sucessfully";
ViewPanel.Visible = true;
}
else
{
lblmsg.Text = "Please Check all the fields";
}
BindGridView();
ProductInfo prdctinfo = new ProductInfo();
if (stockType == "In")
{
prdctinfo.Quantity += quantity;
}
if (stockType == "Out")
{
prdctinfo.Quantity -= quantity;
}
}
catch (Exception ex)
{
if (ex is FormatException)
{
lblmsg.Text = "Character value are not allowed";
}
else
{
lblmsg.Text = ex.Message;
}
}
}
Put the breakpoint somewhere where it hits. Look at the call stack and step over to the point when you find why it is not going to the method you want to trigger.
Can't do much without more information.
Hope this helps
I saw few unwanted code's
1) please remove the ValidationGroup="vg1" in your all asp.net controls except button .
2) Don't use panel , some time the button click not working on using panel control, so please use table instead of panel .(or remove the asp:panel control )
3) and must check the button click event same as server side .
4) If you give me our server side code then i will response you !!
Below is the code for what i have started for my project currently. I am updating the new
code. I am getting an error of Gridview1 does not exist.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title spellcheck="true"Glossary</title>
<style type="text/css">
.auto-style1 {
width: 208px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div style="margin-left: 720px">
<asp:Login ID="Login1" runat="server" BackColor="#F7F6F3" BorderColor="#E6E2D8" BorderPadding="4" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#333333">
<InstructionTextStyle Font-Italic="True" ForeColor="Black" />
<LayoutTemplate>
<table cellpadding="1" cellspacing="0" style="border-collapse:collapse;">
<tr>
<td class="auto-style1">
<table cellpadding="0">
<tr>
<td align="center" colspan="2">Log In</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
</td>
<td>
<asp:TextBox ID="UserName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
</td>
<td>
<asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td colspan="2">
<asp:CheckBox ID="RememberMe" runat="server" Text="Remember me next time." />
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color:Red;">
<asp:Literal ID="FailureText" runat="server" ClientIDMode="AutoID"></asp:Literal>
</td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" ValidationGroup="Login1" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</LayoutTemplate>
<LoginButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284775" />
<TextBoxStyle Font-Size="0.8em" />
<TitleTextStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="0.9em" ForeColor="White" />
</asp:Login>
</div>
<asp:SqlDataSource ID="TedGlossary" runat="server" ConnectionString="<%$ ConnectionStrings:Glsry_Taylor %>" SelectCommand="SELECT [TermText], [DefNbr], [DefVerNbr], [DefText], [AmplifyingExplanationText], [SeeAlsoText], [AuthoritativeSrcText], [ScopeName], [DomnName], [GovernanceStateName], [LastUpdtTimestamp] FROM [Glossary] ORDER BY [TermText]"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
" DataKeyNames="TermText,DefNbr,DefVerNbr" DataSourceID="TedGlossary" EnableSortingAndPagingCallbacks="True">
<Columns>
<asp:BoundField DataField="TermText" HeaderText="Term" ReadOnly="True" SortExpression="TermText" />
<asp:BoundField DataField="DefNbr" HeaderText="Definition #" ReadOnly="True" SortExpression="DefNbr" />
<asp:BoundField DataField="DefVerNbr" HeaderText="Definition Vers #" ReadOnly="True" SortExpression="DefVerNbr" />
<asp:BoundField DataField="DefText" HeaderText="Definition" SortExpression="DefText" />
<asp:BoundField DataField="AmplifyingExplanationText" HeaderText="Amplifying Explanation" SortExpression="AmplifyingExplanationText" />
<asp:BoundField DataField="SeeAlsoText" HeaderText="See Also" SortExpression="SeeAlsoText" />
<asp:BoundField DataField="AuthoritativeSrcText" HeaderText="Authoritative Source" SortExpression="AuthoritativeSrcText" />
<asp:BoundField DataField="ScopeName" HeaderText="Scope Name" SortExpression="ScopeName" />
<asp:BoundField DataField="DomnName" HeaderText="Domn Name" SortExpression="DomnName" />
<asp:BoundField DataField="GovernanceStateName" HeaderText="Governance State" SortExpression="GovernanceStateName" />
<asp:BoundField DataField="LastUpdtTimestamp" HeaderText="Last Update" SortExpression="LastUpdtTimestamp" />
</Columns>
</asp:GridView>
</form>
<script>
$(function () {
$('#<%=GridView1.ClientID%>').dataTable();
});
</script>
</body>
</html>
Is there something that i am missing. I need to be able to filter results using some sort of search.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Home
{
public partial class Glossary : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GridView1.PreRender += new EventHandler(GridView1_PreRender);
}
protected void GridView1_PreRender(object sender, EventArgs e)
{
if (GridView1.Rows.Count > 0)
{
//forces grid to render thead/th elements
GridView1.UseAccessibleHeader = true;
GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
}
}
}
}
(I think you are referring to the datatables jquery plugin.)
Yes, it's possible. You need to make sure your GridView generates the thead tags in your table, so you need to do the following:
protected void Page_Load(object sender, EventArgs e)
{
GridView1.PreRender += new EventHandler(GridView1_PreRender);
}
protected void GridView1_PreRender(object sender, EventArgs e)
{
if (GridView1.Rows.Count > 0)
{
//forces grid to render thead/th elements
GridView1.UseAccessibleHeader = true;
GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
}
}
Now you can simply do:
<script>
$(function(){
$('#<%=Gridview1.ClientID%>').dataTable();
});
</script>
Yes, this is definitely possible, but I've never tried it with a SqlDataSource. Here's how I'd do it:
Add a TextBox and Button to your page.
On the Button's Click event, you'll want to read the text in your TextBox and query your database.
This is where it can diverge. You can use the old-school ADO.NET (SqlConnection, SqlCommand, etc), or you can do it as LINQ to Entities, which is the newer way. Which way are you more familiar with? I'll tailor the answer based on your response.
Here is a code that I have in one of my ASPX pages:
<asp:GridView
ID="GridView1"
runat="server"
AutoGenerateColumns="False"
HorizontalAlign="Center"
ShowHeader="False"
DataSourceID="sqlTEST1">
<Columns>
<asp:BoundField DataField="stale" Visible="false" />
<asp:BoundField DataField="bad" Visible="false" />
<asp:BoundField DataField="ping" Visible="false" />
<asp:BoundField DataField="max_tags" Visible="false" />
<asp:BoundField DataField="aval_chck" Visible="false" />
<asp:TemplateField>
<ItemTemplate>
<%
if (Eval("aval_chck").ToString()=="1")
{
<table border="0" cellpadding="2" cellspacing="1">
<tr>
<td class="rowsBLACKMAINOFF" colspan="3"><asp:Label ID="Label2" runat="server" Text='<%# Bind("instalacja") %>'></asp:Label></td>
</tr>
<tr>
<td class="rowsBLACKROWOFF"><asp:Label ID="Label2" runat="server" Text='<%# Bind("stale") %>'></asp:Label></td>
<td class="rowsBLACKROWOFF"><asp:Label ID="Label3" runat="server" Text='<%# Bind("bad") %>'></asp:Label></td>
<td class="rowsBLACKROWOFF"><asp:Label ID="Label4" runat="server" Text='<%# Bind("ping") %>'></asp:Label></td>
</tr>
</table>
}
else
{
<table border="0" cellpadding="2" cellspacing="1">
<tr>
<td class="rowsBLACKMAIN" colspan="3"><asp:Label ID="Label2" runat="server" Text='<%# Bind("instalacja") %>'></asp:Label></td>
</tr>
<tr>
<td class="rowsNORMALc"> </td>
<td class="rowsNORMALc"> </td>
<td class="rowsNORMALc"> </td>
</tr>
</table>
}
%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I know it doesn't work at all.
I only wrote logically what I want to achieve
I would like to make that statement work or do something similar to that.
Any ideas?
Try GridView.RowDataBound Event
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx