Is anyone able to understand why m I getting this error?
Uncaught Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: Object reference not set to an instance of an object.
SOURCE: ScriptResource.axd
So here is the thing...
I have a button when first clicked (after first site access) works, but after that I always get the error. I tried to debug the subject by putting a debug point at the first line in Page_Load event but its not even getting there.
The error is showing before that on that ScriptResources.axd file which is made of javascript so i tried to debug it but i don't really understand what is going on so i couldn't find the problem.
From what i can understand, somehow, when i first click the button, i must not being initialize some controll i should, but i just can't figure it out.
button id = btnFiltra
HTML
<body>
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<script type="text/javascript">
Sys.Application.add_load(onPageLoad);
</script>
<asp:Panel runat="server" ID="pHeader" CssClass="PVHeaderBackground">
<img alt="Planview" src="Images/logo_planview.png" class="PVLogoBackImgleft"/>
<div id="PTLogo" class="PTLogosRight">
<img src="Images/logo_meo_preto.png" alt="Meo" style="vertical-align:middle; margin-top:auto; margin-bottom:auto"/>
<img src="Images/Ptlogo.jpg" alt="PT" style="height:50px; width:auto; margin-left:10px; vertical-align:middle;margin-top:auto; margin-bottom:auto"/>
</div>
</asp:Panel>
<asp:UpdatePanel ID="upBody" runat="server" UpdateMode="Conditional" >
<ContentTemplate>
<asp:Panel runat="server" ID="pOpcoesGlobais" >
<asp:Button ID="btnExtrair" runat="server" OnClientClick="umProjetoApenas()" OnClick="btnExtrair_OnClick" Text="Extrair Dados"/>
<asp:Button ID="btnAtualizar" runat="server" OnClientClick="umProjetoApenas()" OnClick="btnAtualizar_OnClick" Text="Atualizar Dados"/>
</asp:Panel>
<asp:Panel runat="server" ID="pTarefaOkFaturar" Visible="true" style="display:none;" Width="100%" Height="100%" >
<div style="width:100%; height:10%">
<b>Ao confirmar que a tarefa pode ser faturada, todas as parcelas sem documento passarão a ser faturadas de forma automática.</b>
</div>
<div style="width:100%;">
<asp:GridView runat="server" ID="gvCheckParcelas" CssClass="PVPortlet"></asp:GridView>
</div>
<div style="width:100%;position: absolute;bottom: 10px;">
<asp:Button ID="btnOkFaturarCancelar" runat="server" Text="Cancelar" OnClick="btnOkFaturarCancelar_OnClick" style="float:left;margin-left: 10px;"/>
<asp:Button ID="btnOkFaturarOk" runat="server" Text="Concordo" OnClick="btnOkFaturarOk_OnClick" style="float:right;margin-right: 10px;" />
</div>
</asp:Panel>
<asp:Panel runat="server" ID="pBody">
<asp:UpdatePanel ID="upFiltros" runat="server">
<ContentTemplate>
<asp:Label ID="lCliente" runat="server" Text="Cliente"/>
<asp:TextBox ID="txbCliente" runat="server"/>
<asp:PopupControlExtender ID="txbCliente_PopupControlExtender" runat="server" Enabled="True" ExtenderControlID="" TargetControlID="txbCliente"
PopupControlID="pPopUpCliente" Position="Bottom" >
</asp:PopupControlExtender>
<asp:Panel ID="pPopUpCliente" runat="server" Height="116px" BorderStyle="Solid" BorderWidth="2px" Direction="LeftToRight" ScrollBars="Auto" BackColor="#CCCCCC" Style="display: none" >
<asp:CheckBoxList ID="cblCliente" runat="server" DataTextField="DESCRICAO" onChange="uncheckOnTodos(this)" DataValueField="ID" AutoPostBack="False" AppendDataBoundItems="True">
<asp:ListItem Text="Todos" Value="all" Selected="False"></asp:ListItem>
</asp:CheckBoxList>
</asp:Panel>
<asp:Label ID="lPedido" runat="server" Text="Pedido"/>
<asp:TextBox ID="txbPedido" runat="server"/>
<asp:PopupControlExtender ID="txbPedido_PopupControlExtender" runat="server"
Enabled="True" ExtenderControlID="" TargetControlID="txbPedido"
PopupControlID="pPopUpPedido" Position="Bottom" >
</asp:PopupControlExtender>
<asp:Panel ID="pPopUpPedido" runat="server" Height="116px"
BorderStyle="Solid" BorderWidth="2px" Direction="LeftToRight"
ScrollBars="Auto" BackColor="#CCCCCC" Style="display: none" >
<asp:CheckBoxList ID="cblPedido" runat="server"
DataTextField="DESCRICAO" onChange="uncheckOnTodos(this)"
DataValueField="ID" AutoPostBack="False" AppendDataBoundItems="True">
<asp:ListItem Text="Todos" Value="all" Selected="False"></asp:ListItem>
</asp:CheckBoxList>
</asp:Panel>
<asp:Label ID="lProjeto" runat="server" Text="Projeto"/>
<asp:TextBox ID="txbProjeto" runat="server"/>
<asp:PopupControlExtender ID="txbProjeto_PopupControlExtender" runat="server"
Enabled="True" ExtenderControlID="" TargetControlID="txbProjeto"
PopupControlID="pPopUpProjeto" Position="Bottom" >
</asp:PopupControlExtender>
<asp:Panel ID="pPopUpProjeto" runat="server" Height="116px"
BorderStyle="Solid" BorderWidth="2px" Direction="LeftToRight" ScrollBars="Auto" BackColor="#CCCCCC" Style="display: none" >
<asp:CheckBoxList ID="cblProjeto" runat="server"
DataTextField="DESCRICAO" onChange="uncheckOnTodos(this)"
DataValueField="ID" AutoPostBack="False" AppendDataBoundItems="True">
<asp:ListItem Text="Todos" Value="all" Selected="False"></asp:ListItem>
</asp:CheckBoxList>
</asp:Panel>
<asp:Button runat="server" ID="btnFiltra" Text="Pesquisar"
onclick="btnFiltra_Click"/>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="uprgTarefas" runat="server" AssociatedUpdatePanelID="upTarefas" DisplayAfter="2000" >
<ProgressTemplate>Loading...</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="upTarefas" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnFiltra" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="btnAtualizar" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="btnExtrair" EventName="Click" />
</Triggers>
<ContentTemplate>
<div id="dTabelaTarefaHeader" class="PVPortletHeader">
<div id="dTabelaTarefasOpcoes" class="PVPortletHeaderOpcoes"></div>
<b>Tarefas Faturação</b>
</div>
<asp:Panel runat="server" ID="pgvTarefasEmpty" Visible="false">
<table class="PVPortlet">
<tbody>
<tr>
<th></th>
<th>ID</th>
<th>Projeto</th>
<th>Tarefa</th>
<th>Cliente</th>
<th>Pedido</th>
<th>Inicio</th>
<th>Fim</th>
<th>Faturar?</th>
<th>Planeado</th>
<th>Remanescente</th>
<th>Faturado</th>
<th>Entidade</th>
</tr>
<tr>
<td colspan="13">Sem dados...</td>
</tr>
</tbody>
</table>
</asp:Panel>
<asp:GridView ID="gvTarefas" runat="server" AutoGenerateSelectButton="true"
AutoGenerateColumns="false" CssClass="PVPortlet" SelectedRowStyle-CssClass="PVPortletSelectedRow"
onselectedindexchanged="gvTarefas_SelectedIndexChanged" DataKeyNames="ID"
OnRowCreated="gvTarefas_OnRowCreated">
<columns>
<asp:BoundField DataField="ID" HtmlEncode="false" HeaderText="ID" />
<asp:BoundField DataField="Projeto" HtmlEncode="false" HeaderText="Projeto" />
<asp:BoundField DataField="Tarefa" HtmlEncode="false" HeaderText="Tarefa" />
<asp:BoundField DataField="Cliente" HtmlEncode="false" HeaderText="Cliente" />
<asp:BoundField DataField="Pedido" HtmlEncode="false" HeaderText="Pedido" />
<asp:BoundField DataField="DataInicio" DataFormatString="{0:dd-MM-yyyy}" HeaderText="Inicio" />
<asp:BoundField DataField="DataFim" DataFormatString="{0:dd-MM-yyyy}" HeaderText="Fim" />
<asp:TemplateField HeaderText="Faturar?">
<ItemTemplate>
<asp:CheckBox runat="server" ID="cbFaturar" Checked='<%# Eval("ProntoAFaturar") %>' AutoPostBack="true" OnCheckedChanged="cb_OnCheckedChanged"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Planeado" HeaderText="Planeado" />
<asp:BoundField DataField="Remanescente" HeaderText="Remanescente" />
<asp:BoundField DataField="Faturado" HeaderText="Faturado" />
<utl:CompositeBoundField HeaderText="Entidade" DataField="EntidadeResponsavel.Descricao" />
</columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<br />
<br />
<asp:UpdateProgress ID="uprgParcelas" runat="server"
AssociatedUpdatePanelID="upParcelas" DisplayAfter="2000">
<ProgressTemplate>Loading...</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="upParcelas" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:asyncpostbacktrigger controlid="gvTarefas"
EventName="SelectedIndexChanged" />
<asp:asyncpostbacktrigger controlid="gvParcelas" EventName="RowEditing" />
</Triggers>
<ContentTemplate>
<div ID="dTabelaParcelasHeader" class="PVPortletHeader">
<b>Parcelas Faturação</b>
</div>
<asp:Panel ID="pgvParcelasEmpty" runat="server" Visible="false">
<table class="PVPortlet">
<tbody>
<tr>
<th></th>
<th>ID</th>
<th>Auto</th>
<th>DataEnvio</th>
<th>Descrição</th>
<th>Valor</th>
</tr>
<tr>
<td colspan="6">Sem dados...</td>
</tr>
</tbody>
</table>
</asp:Panel>
<asp:GridView ID="gvParcelas" runat="server" AutoGenerateColumns="false" AutoGenerateDeleteButton="true" AutoGenerateEditButton="true"AutoGenerateSelectButton="true" CssClass="PVPortlet" DataKeyNames="ID" OnRowCancelingEdit="gvParcelas_OnRowCancelingEdit"
OnRowCommand="gvParcelas_OnRowCommand" OnRowCreated="gvParcelas_OnRowCreated" OnRowDeleting="gvParcelas_OnRowDeleting" OnRowEditing="gvParcelas_RowEditing" OnRowUpdating="gvParcelas_OnRowUpdating" Visible="false" SelectedRowStyle-CssClass="PVPortletSelectedRow"
OnSelectedIndexChanged="obterDocumento_OnSeacrh" ShowFooter="True">
<Columns>
<asp:TemplateField HeaderText="ID">
<EditItemTemplate>
<asp:Label ID="lIDParcela" runat="server" Text='<%# Eval("ID") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lIDParcela" runat="server" Text='<%# Eval("ID") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="btnParcelaNovo" runat="server" CommandName="Insert" Text="Novo" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Auto">
<EditItemTemplate>
<asp:CheckBox ID="cbAuto" runat="server" Checked='<%# Eval("Auto") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="cbAuto" runat="server" Checked='<%# Eval("Auto") %>' Enabled="false"/>
</ItemTemplate>
<FooterTemplate>
<asp:CheckBox ID="cbAuto" runat="server" Checked="true" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DataEnvio">
<EditItemTemplate>
<asp:TextBox ID="txbDataEnvio" runat="server" Text='<%# Eval("DataEnvio","{0:dd-MM-yyyy}") %>' />
<asp:CalendarExtender ID="txbDataEnvio_CalendarExtender" runat="server"
DefaultView="Months" Enabled="True" Format="MM-yyyy" PopupPosition="BottomLeft"
TargetControlID="txbDataEnvio">
</asp:CalendarExtender>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lDataEnvio" runat="server"
Text='<%# Eval("DataEnvio","{0:dd-MM-yyyy}") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txbDataEnvio" runat="server" Text="" />
<asp:CalendarExtender ID="txbDataEnvio_CalendarExtender" runat="server"
DefaultView="Months" Enabled="True" Format="MM-yyyy" PopupPosition="BottomLeft"
TargetControlID="txbDataEnvio">
</asp:CalendarExtender>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Descrição">
<EditItemTemplate>
<asp:TextBox ID="txbDescricao" runat="server" Text='<%# Eval("Descricao") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lDescricao" runat="server" Text='<%# Eval("Descricao") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txbDescricao" runat="server" Text="" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Valor">
<EditItemTemplate>
<asp:TextBox ID="txbValor" runat="server" Text='<%# Eval("Valor") %>' />
<asp:FilteredTextBoxExtender ID="txbValor_FilteredTextBoxExtender" runat="server" FilterType="Custom" TargetControlID="txbValor" ValidChars="0123456789,">
</asp:FilteredTextBoxExtender>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lValor" runat="server" Text='<%# Eval("Valor") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txbValor" runat="server" Text="" />
<asp:FilteredTextBoxExtender ID="txbValor_FilteredTextBoxExtender"
runat="server" FilterType="Numbers" TargetControlID="txbValor">
</asp:FilteredTextBoxExtender>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="uprgDocumentos" runat="server"
AssociatedUpdatePanelID="upDocumentos" DisplayAfter="2000">
<ProgressTemplate>Loading...</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="upDocumentos" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div ID="dTabelaDocumentosHeader" class="PVPortletHeader">
<div ID="dTabelaDocumentosOpcoes" class="PVPortletHeaderOpcoes">
<asp:Label ID="lDocInicio" runat="server" Text="Inicio" style="float:left;"></asp:Label>
<asp:TextBox ID="txbInicio" runat="server" style="float:left;"></asp:TextBox>
<asp:CalendarExtender ID="txbInicio_CalendarExtender" runat="server" Enabled="True" Format="MM-yyyy" TargetControlID="txbInicio">
</asp:CalendarExtender>
<asp:Label ID="lDocFim" runat="server" Text="Fim" style="float:left;"></asp:Label>
<asp:TextBox ID="txbFim" runat="server" style="float:left;"></asp:TextBox>
<asp:CalendarExtender ID="txbFim_CalendarExtender" runat="server" Enabled="True" Format="MM-yyyy" TargetControlID="txbFim">
</asp:CalendarExtender>
<asp:Button ID="btnDocFiltro" runat="server" Text="Pesquisar" style="float:left;" OnClick="obterDocumento_OnSeacrh"/>
</div>
<b>Documentos Faturação</b>
<asp:Button ID="btnNovoDocumento" runat="server" OnClientClick="abrirDocumento(0);" Text="Novo" style="float:right;"/>
</div>
<asp:Panel ID="pgvDocumentosEmpty" runat="server" Visible="false">
<table class="PVPortlet">
<tbody>
<tr>
<th></th>
<th>ID</th>
<th>Fatura</th>
<th>Enviado</th>
<th>Estado</th>
<th>Tipo</th>
<th>Descrição</th>
<th>Valor</th>
</tr>
<tr>
<td colspan="8">Sem dados...</td>
</tr>
</tbody>
</table>
</asp:Panel>
<asp:GridView ID="gvDocumentos" runat="server" AutoGenerateColumns="false" AutoGenerateDeleteButton="false" AutoGenerateEditButton="false" AutoGenerateSelectButton="false" CssClass="PVPortlet">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton Text="Abrir" runat="server" ID="lbtnAbrirDoc" OnClientClick='<%#"abrirDocumento(" + Eval("ID") + ");"%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ID" HeaderText="ID" HtmlEncode="false" />
<asp:BoundField DataField="NFATURA" HeaderText="Fatura" HtmlEncode="false" />
<asp:BoundField DataField="EnviadoA" DataFormatString="{0:dd-MM-yyyy}" HeaderText="Enviado" HtmlEncode="false" />
<utl:CompositeBoundField DataField="Estado.Descricao" HeaderText="Estado" HtmlEncode="false" />
<utl:CompositeBoundField DataField="Tipo.Descricao" HeaderText="Tipo" HtmlEncode="false" />
<asp:TemplateField HeaderText="Descrição">
<ItemTemplate>
<asp:Label ID="lCabecalho" runat="server" Text='<%#Eval("Cabecalho").ToString().Cut(30,true)+"-"+Eval("Periodo")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Valor" HeaderText="Valor" HtmlEncode="false" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
Server SIde
protected void Page_Load(object sender, EventArgs e)
{
userName = HttpContext.Current.User.Identity.Name.ToString().ToUpper();
sessionID = Session.SessionID;
if (!IsPostBack)
{
Session["USER_" + sessionID] = userName;
Session["TAREFAS_INV_" + sessionID] = null;
Session["PARCELAS_"+sessionID] = null;
Session["DOCUMENTOS_"+sessionID] = null;
carregaDadosFiltros();
string idPrj = null;
obtemParametrosEntrada(ref idPrj);
pgvDocumentosEmpty.Visible = true;
pgvParcelasEmpty.Visible = true;
pgvTarefasEmpty.Visible = true;
gvDocumentos.Visible = false;
gvParcelas.Visible = false;
gvTarefas.Visible = false;
if (!string.IsNullOrEmpty(idPrj))
{
bool filtra = true;
if (cblProjeto.Items.FindByValue(idPrj) != null)
{
cblProjeto.SelectedValue = idPrj;
}
else
{
string nome = InvDataAccess.obterNomeProjeto(idPrj);
if(!string.IsNullOrEmpty(nome))
{
ListItem prj = new ListItem(nome, idPrj, true);
cblProjeto.Items.Add(prj);
cblProjeto.SelectedValue = prj.Value;
}
else
filtra = false;
}
cblCliente.SelectedValue = "all";
cblPedido.SelectedValue = "all";
if(filtra) btnFiltra_Click(null, null);
}
}
else
{
userName = Session["USER_" + sessionID] as string;
DateTime inicio = DateTime.MinValue, fim = DateTime.MaxValue;
if (!DateTime.TryParseExact(txbInicio.Text, txbInicio_CalendarExtender.Format, null, System.Globalization.DateTimeStyles.None, out inicio))
txbInicio_CalendarExtender.SelectedDate = DateTime.MinValue;
if (!DateTime.TryParseExact(txbFim.Text, txbFim_CalendarExtender.Format, null, System.Globalization.DateTimeStyles.None, out fim))
txbFim_CalendarExtender.SelectedDate = DateTime.MaxValue;
if (Session["TAREFAS_INV_"+sessionID] != null)
tarefas = (Dictionary<int, InvTarefas>)Session["TAREFAS_INV_"+sessionID];
if (Session["PARCELAS_"+sessionID] != null)
{
parcelas = (Dictionary<int, InvParcelaTarefa>)Session["PARCELAS_"+sessionID];
gvParcelas.DataSource = parcelas.Values.ToList();
}
if (Session["DOCUMENTOS_"+sessionID] != null)
{
documentos = (Dictionary<int, InvDocumento>)Session["DOCUMENTOS_"+sessionID];
gvDocumentos.DataSource = documentos.Values.ToList();
}
}
}
protected void btnFiltra_Click(object sender, EventArgs e)
{
tarefas.Clear();
List<string> idCliente, idPedido, idProjeto;
DateTime inicio, fim;
idCliente = cblCliente.Items.Cast<ListItem>().Where(i => i.Selected).Select(i => i.Value).ToList();
idPedido = cblPedido.Items.Cast<ListItem>().Where(i => i.Selected).Select(i => i.Value).ToList();
idProjeto = cblProjeto.Items.Cast<ListItem>().Where(i => i.Selected).Select(i => i.Value).ToList();
inicio = DateTime.MinValue;
fim = DateTime.MaxValue;
List<InvTarefas> tars = InvTarefas.getInvTarefas(new List<string>{"all"}, idCliente, idPedido, idProjeto, inicio, fim);
if (tars != null && tars.Count > 0)
{
foreach (InvTarefas tar in tars)
{
tarefas.Add(tar.ID, tar);
}
this.Session["TAREFAS_INV_"+sessionID] = tarefas;
gvTarefas.DataSource = tarefas.Values.ToList();
gvTarefas.DataBind();
pgvTarefasEmpty.Visible = false;
gvTarefas.Visible = true;
}
else
{
this.Session["TAREFAS_INV_"+sessionID] = null;
pgvTarefasEmpty.Visible = true;
gvTarefas.Visible = false;
}
}
After some help from a colleague, we found that the gvTarefas_OnRowCreated event was firing before the Page_load and that the code inside was trowing null exception.
I was also advised to change my event to OnRowDataBound.
Also, for those of you who didn't knew you can set (when in trouble, otherwise is to much load) VS to stop on the line that throwed the exception by going Debug->Exceptions->Throw in Common Language Runtime Exceptions. If i knew this I probably had solved it right away.
Now, about the strange OnRowCreated before Page_Load, i still can't understand, but something tells me it's because of my UpdatePanel upBody that catches most of the page and its update mode is in Always (is the default value).
Last, i'm putting my OnRowCreated code
protected void gvTarefas_OnRowCreated(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
InvTarefas tar = e.Row.DataItem as InvTarefas;
if (tar.EntidadeResponsavel != InvEntidadeResponsavel.PV_PROPRIO)
{
e.Row.Enabled = false;
e.Row.CssClass = "PVPortlet_DisabledRoW";
}
}
}
Related
I have a parent grid GVInvoiceDet. CRUD operation on this grid is working fine. In each row of the parent, I have child grid GVTaxDetails which opens on click of image ie expand/collapse feature.
I am looking for CRUD within child grid also. But when I click on edit within child, the texbox for editing doesn't appear and the parent grid collapses.
Here is child grid rowediting code
protected void GVTaxDetails_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView gvTemp = (GridView)sender;
gvUniqueID = gvTemp.UniqueID;
//gvEditIndex = e.NewEditIndex;
gvTemp.EditIndex = e.NewEditIndex;
GVInvoiceDet.DataBind();
}
Parent row editing code
protected void GVInvoiceDet_RowEditing(object sender, GridViewEditEventArgs e)
{
GVInvoiceDet.EditIndex = e.NewEditIndex;
GVInvoiceDet.DataBind();
BindItemGrid();
}
ASPX file :
<asp:GridView ID="GVInvoiceDet" runat="server" Width="100%" AutoGenerateColumns="False"
HorizontalAlign="Left" BorderStyle="Outset" OnRowCancelingEdit="GVInvoiceDet_RowCancelingEdit"
OnRowEditing="GVInvoiceDet_RowEditing" OnRowDataBound="GVInvoiceDet_RowDataBound" ShowFooter="True"
OnRowCommand="GVInvoiceDet_RowCommand" OnRowUpdating="GVInvoiceDet_RowUpdating"
OnRowDeleting="GVInvoiceDet_RowDeleting" OnRowDeleted="GVInvoiceDet_RowDeleted"
OnRowUpdated="GVInvoiceDet_RowUpdated" AllowSorting="True" DataSourceID="DSItemGrid" DataKeyNames="invoiceno,itemcd">
<HeaderStyle BackColor="#0000ff" ForeColor="Yellow" />
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<EditRowStyle BackColor="#FFFFCC" ForeColor="#330099" />
<AlternatingRowStyle BackColor="#FE9CD5" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<a href="javascript:expandcollapse('div<%# Eval("itemcd") %>', 'one');">
<img id="imgdiv<%# Eval("itemcd") %>" alt="Click to show/hide Tax Details <%# Eval("itemcd") %>" border="0" src="Images/plus.png" />
</a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="10%" HeaderText="Item Code" SortExpression="itemcd">
<ItemTemplate>
<asp:Label ID="lblItemCode" runat="server" Text='<%# Eval("itemcd")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtItemCode" Width="90%" runat="server" Text='<%# Eval("itemcd")%>' Enabled="false"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtItemCode" Width="90%" runat="server" Text='' Enabled="false"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="10%" HeaderText="HSN Code" SortExpression="hsncd">
<ItemTemplate>
<asp:Label ID="lblItemHSNCode" runat="server" Text='<%# Eval("hsncd")%>'></asp:Label><asp:HiddenField ID="hdnItemGST" runat="server" Value='<%# Eval("itempercentage") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtItemHSN" Width="90%" runat="server" Text='<%# Eval("hsncd")%>' Enabled="false"></asp:TextBox><asp:HiddenField ID="hdnEditItemGST" runat="server" Value='<%# Eval("itempercentage") %>' />
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtItemHSN" Width="90%" runat="server" Text='' Enabled="false"></asp:TextBox><asp:HiddenField ID="hdnFooterItemGST" runat="server" Value='<%# Eval("itempercentage") %>' />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="25%" HeaderText="Item Description" SortExpression="itemdesc">
<ItemTemplate>
<asp:Label ID="lblItemDesc" runat="server" Text='<%# Eval("itemdesc")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblItemDesc" runat="server" Text='<%# Eval("itemdesc")%>' Visible="false"></asp:Label><asp:HiddenField ID="hdnItemDesc" runat="server" Value='<%# String.Format("{0}-{1}-{2}",Eval("itemcd"),Eval("hsncd"),Eval("itempercentage")) %>' />
<asp:DropDownList ID="eddlItemDesc" runat="server" AutoPostBack="true" OnSelectedIndexChanged="eddlItemDesc_SelectedIndexChanged"></asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="fddlItemDesc" runat="server" AutoPostBack="true" OnSelectedIndexChanged="fddlItemDesc_SelectedIndexChanged"></asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="5%" HeaderText="Quantity">
<ItemTemplate>
<asp:Label ID="lblItemQty" runat="server" Text='<%# Eval("quantity")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtItemQty" Width="90%" runat="server" Text='<%# Eval("quantity")%>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtItemQty" Width="90%" MaxLength="100" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="5%" HeaderText="Unit Rate">
<ItemTemplate>
<asp:Label ID="lblItemUnitRate" runat="server" Text='<%# Eval("unitrate")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtItemUnitRate" Width="90%" runat="server" Text='<%# Eval("unitrate")%>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtItemUnitRate" Width="90%" MaxLength="100" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="5%" HeaderText="Unit Value">
<ItemTemplate>
<asp:Label ID="lblItemUnitValue" runat="server" Text='<%# Eval("unitvalue")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtItemUnitValue" Width="90%" runat="server" Text='<%# Eval("unitvalue")%>' Enabled="false"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtItemUnitValue" Width="90%" MaxLength="100" runat="server" Enabled="false"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="5%" HeaderText="Final Value">
<ItemTemplate>
<asp:Label ID="lblItemFinalValue" runat="server" Text=''></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtItemFinalValue" Width="90%" runat="server" Text='' Enabled="false"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtItemFinalValue" Width="90%" MaxLength="100" runat="server" Enabled="false"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" HeaderText="Edit" />
<asp:TemplateField HeaderText="Delete" ItemStyle-Width="5%">
<ItemTemplate>
<asp:LinkButton ID="linkDeleteInvoiceItem" CommandName="DeleteItem" runat="server">Delete</asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="linkAddInvoiceItem" CommandName="AddItem" runat="server">Add</asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<tr>
<td colspan="100%">
<div id="div<%# Eval("itemcd") %>" style="display: none; position: relative; left: 15px; overflow: auto; width: 97%">
<asp:GridView ID="GVTaxDetails" BackColor="White" Width="100%" Font-Size="Small" AutoGenerateColumns="false"
runat="server" DataKeyNames="invoiceno,itemcd,valuecd" ShowFooter="True" OnRowUpdating="GVTaxDetails_RowUpdating"
OnRowCommand="GVTaxDetails_RowCommand" OnRowEditing="GVTaxDetails_RowEditing" GridLines="None"
OnRowUpdated="GVTaxDetails_RowUpdated" OnRowCancelingEdit="GVTaxDetails_CancelingEdit"
OnRowDataBound="GVTaxDetails_RowDataBound" OnRowDeleting="GVTaxDetails_RowDeleting" OnRowDeleted="GVTaxDetails_RowDeleted"
ShowHeaderWhenEmpty="true" BorderStyle="Double" BorderColor="#0083C1">
<RowStyle BackColor="Gainsboro" />
<AlternatingRowStyle BackColor="White" />
<HeaderStyle BackColor="#0083C1" ForeColor="White" />
<FooterStyle BackColor="White" />
<Columns>
<asp:TemplateField ItemStyle-Width="5%" HeaderText="SL No">
<ItemTemplate>
<asp:Label ID="lblViewTaxSlno" runat="server" Text='<%# Eval("slno")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtViewTaxSlno" runat="server" Text='<%# Eval("slno")%>' Enabled="false"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtViewTaxSlno" MaxLength="3" Width="80%" runat="server" Text='<%# Convert.ToInt32(Container.DataItemIndex) + 1 %>' Enabled="false"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="15%" HeaderText="Value">
<ItemTemplate>
<asp:HiddenField ID="hdnViewTaxDesc" runat="server" Value='<%# Eval("valuecd") %>' />
<asp:Label ID="lblViewTaxDesc" runat="server" Text='<%# Eval("valuedesc")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:HiddenField ID="hdnViewTaxDesc" runat="server" Value='<%# Eval("valuecd") %>' />
<asp:DropDownList ID="eddlViewTaxDesc" Width="90%" runat="server" AutoPostBack="true" OnSelectedIndexChanged="eddViewTaxDesc_SelectedIndexChanged"></asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:HiddenField ID="hdnViewTaxDesc" runat="server" Value='<%# Eval("valuecd") %>' />
<asp:DropDownList ID="fddViewTaxDesc" Width="90%" runat="server" OnSelectedIndexChanged="fddlViewTaxDesc_SelectedIndexChanged"></asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="3%" HeaderText="Amount">
<ItemTemplate>
<asp:Label ID="lblViewTaxAmount" runat="server" Text='<%# Eval("value")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtViewTaxAmount" runat="server" Text='<%# Eval("value")%>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtViewTaxAmount" runat="server" Text='<%# Eval("value")%>'></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="7%" HeaderText="Ref. Sl No">
<ItemTemplate>
<asp:Label ID="lblViewTaxRefNo" runat="server" Text='<%# Eval("refslno")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:HiddenField ID="hdnViewTaxRefNo" runat="server" Value='<%# Eval("refslno") %>' />
<asp:DropDownList ID="eddlViewTaxRefNo" Width="90%" runat="server" AutoPostBack="false"></asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="fddViewTaxRefNo" Width="90%" runat="server" AutoPostBack="false"></asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="10%" HeaderText="Tax-Mode">
<ItemTemplate>
<asp:Label ID="lblViewTaxMode" runat="server" Text='<%# Eval("absper").ToString()=="A"?"Absolute":"Percentage"%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:HiddenField ID="hdnViewTaxMode" runat="server" Value='<%# Eval("absper") %>' />
<asp:DropDownList ID="eddlViewTaxMode" Width="90%" runat="server" AutoPostBack="false">
<asp:ListItem Value="-1" Text="-Select Mode-" Selected="True"></asp:ListItem>
<asp:ListItem Value="A" Text="Absolute"></asp:ListItem>
<asp:ListItem Value="P" Text="Percentage"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="fddlViewTaxMode" Width="95%" runat="server" AutoPostBack="false">
<asp:ListItem Value="-1" Text="-Select Mode-" Selected="True"></asp:ListItem>
<asp:ListItem Value="A" Text="Absolute"></asp:ListItem>
<asp:ListItem Value="P" Text="Percentage"></asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="10%" HeaderText="Operation">
<ItemTemplate>
<asp:Label ID="lblViewTaxOperation" runat="server" Text='<%# Eval("addsub").ToString()=="A"?"Add":"Subtract"%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:HiddenField ID="hdnViewTaxOperation" runat="server" Value='<%# Eval("addsub") %>' />
<asp:DropDownList ID="eddlViewTaxOperation" Width="90%" runat="server" AutoPostBack="false">
<asp:ListItem Value="-1" Text="-Select Operation-" Selected="True"></asp:ListItem>
<asp:ListItem Value="A" Text="Add"></asp:ListItem>
<asp:ListItem Value="S" Text="Subtract"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="fddlViewTaxOperation" Width="90%" runat="server" AutoPostBack="false">
<asp:ListItem Value="-1" Text="-Select Operation-" Selected="True"></asp:ListItem>
<asp:ListItem Value="A" Text="Add"></asp:ListItem>
<asp:ListItem Value="S" Text="Subtract"></asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="3%" HeaderText="Final Amount">
<ItemTemplate>
<asp:Label ID="lblViewTaxFinalAmount" runat="server" Text='<%# Eval("finalvalue")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtViewTaxFinalAmount" runat="server" Text='<%# Eval("finalvalue")%>' Enabled="false"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtViewTaxFinalAmount" runat="server" Text='<%# Eval("finalvalue")%>' Enabled="false"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="Edit" ShowEditButton="True" />
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="linkDeleteTaxDetails" CommandName="Delete" runat="server">Delete</asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="linkAddTaxDetails" CommandName="AddTax" runat="server">Add</asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="DSItemGrid" runat="server" ConnectionString="<%$ ConnectionStrings:GSTCS %>" ProviderName="<%$ ConnectionStrings:GSTCS.ProviderName %>"
SelectCommand="select invoiceno, dt.itemcd itemcd, mast.itemdesc itemdesc, mast.hsncd hsncd, dt.quantity quantity,
mast.unitrate unitrate, dt.unitvalue unitvalue, mast.itempercentage itempercentage
from GSTINVOICEDT dt join GSTITEMMASTER mast on (dt.itemcd = mast.itemcd and dt.unitcode = mast.unitcode and dt.projectcode = mast.projectcode)
where dt.unitcode = :unitCode and dt.projectCode = :projCode and dt.invoiceno = :invoiceNo order by invoiceno, itemcd">
<SelectParameters>
<asp:SessionParameter DefaultValue="05" Name="unitCode" SessionField="unit" />
<asp:SessionParameter DefaultValue="0501" Name="projCode" SessionField="project" />
<asp:SessionParameter DefaultValue="INVOICENO" Name="invoiceNo" SessionField="invoiceNo" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
I got the work done... Posting the code for others if come across similar situation.
In parent rowdatabound have added code to keep the div open and update the editIndex.
protected void GVInvoiceDet_RowDataBound(object sender, GridViewRowEventArgs e) {
GridViewRow row = e.Row;
if(row.RowType == DataControlRowType.Header)
{
return;
}
else if (row.RowType == DataControlRowType.DataRow )
{
//Find Child GridView control
GridView gvTax = new GridView();
gvTax = (GridView)row.FindControl("GVTaxDetails");
if (gvTax.UniqueID == gvUniqueID)
{
gvTax.EditIndex = gvEditIndex;
//Expand the Child grid
ClientScript.RegisterStartupScript(GetType(), "Expand", "<SCRIPT LANGUAGE='javascript'>expandcollapse('div" + ((DataRowView)e.Row.DataItem)["itemcd"].ToString() + "','one');</script>");
}
}
}
expandcollapse is function on aspx side:
function expandcollapse(obj, row) {
var div = document.getElementById(obj);
var img = document.getElementById('img' + obj);
if (div.style.display == "none") {
div.style.display = "block";
if (row == 'alt') {
img.src = "Images/minus.png";
}
else {
img.src = "Images/minus.png";
}
img.alt = "Close View Taxes";
}
else {
div.style.display = "none";
if (row == 'alt') {
img.src = "Images/plus.png";
}
else {
img.src = "Images/plus.png";
}
img.alt = "Expand View Taxes";
}
}
Hi i want to make a footertemplate which can expand and collapse results like this image example in other topic: How do I add FooterTemplate to GridView with BoundFields
I want for default show 1 result, and after clicking in a icon on footertemplate show me more results like 4 or 5, i can show the code, thanks in advance.
The same work i have done on my project! I am pasting that work here. Please go through it, it might help you solving your problem
ASPX:
<asp:GridView Width="100%" border="1" ID="gwProfit" RowStyle-Wrap="true" runat="server" AutoGenerateColumns="false" AlternatingRowStyle-CssClass="alternaterow" RowStyle-VerticalAlign="Bottom" ShowFooter="True" HeaderStyle-Wrap="true" OnRowCommand="gwProfit_RowCommand" OnRowDataBound="gwProfit_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Start Date">
<ItemTemplate>
<div class="input-append">
<asp:TextBox class="input_disabled" ID="txtStartDate" runat="server" Width="110px" Height="22px" Text='<%# Bind("StartDate","{0}") %>'>
</asp:TextBox>
<button class="btn123" ID="ImgStartDate" runat="server" type="button" style="height:25px;">
<i class="icon-calendar"></i>
</button>
</div>
<ajaxToolkit:CalendarExtender ID="StartDate" runat="server" TargetControlID="txtStartDate" PopupButtonID="ImgStartDate" Format="dd-MMM-yyyy">
</ajaxToolkit:CalendarExtender>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox class="input_disabled" ID="txtNewStartDate" runat="server" Width="110px" Height="22px">
</asp:TextBox>
<button class="btn123" ID="ImgStartDate" runat="server" type="button" style="height:25px;">
<i class="icon-calendar"></i>
</button>
</div>
<ajaxToolkit:CalendarExtender ID="StartDate" runat="server" TargetControlID="txtNewStartDate"
PopupButtonID="ImgStartDate" Format="dd-MMM-yyyy">
</ajaxToolkit:CalendarExtender>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="End Date">
<ItemTemplate>
<asp:TextBox class="input_disabled" ID="txtEndDate" runat="server" Width="110px" Height="22px" Text='<%# Bind("EndDate","{0}") %>'>
</asp:TextBox>
<button class="btn123" ID="ImgEndDate" runat="server" type="button" style="height:25px;">
<i class="icon-calendar"></i>
</button>
<ajaxToolkit:CalendarExtender ID="EndDate" runat="server" TargetControlID="txtEndDate"
PopupButtonID="ImgEndDate" Format="dd-MMM-yyyy">
</ajaxToolkit:CalendarExtender>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox class="input_disabled" ID="txtNewEndDate" runat="server" Width="110px" Height="22px">
</asp:TextBox>
<button class="btn123" ID="ImgEndDate" runat="server" type="button" style="height:25px;">
<i class="icon-calendar"></i>
</button>
<ajaxToolkit:CalendarExtender ID="EndDate" runat="server" TargetControlID="txtNewEndDate"
PopupButtonID="ImgEndDate" Format="dd-MMM-yyyy">
</ajaxToolkit:CalendarExtender>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Profit Per Unit">
<ItemTemplate>
<asp:TextBox class="input_disabled" ID="txtProfitPerUnit" Width="100px" Height="22px" runat="server" Text='<%# Bind("ProfitPerUnit","{0}") %>'> </asp:TextBox>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox class="input_disabled" ID="txtNewProfitPerUnit" Width="100px" Height="22px" runat="server" Text="0"/>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action" ControlStyle-Width="14px" FooterStyle-Width="14px">
<ItemTemplate>
<input type="hidden" id="txtrec_status" name="txtrec_status" runat="server"/>
<asp:ImageButton ID="btnDelete" runat="server" CommandName="Delete" ImageUrl="~/images/delete.gif" AlternateText="Delete" CommandArgument="<%# ((GridViewRow) Container).RowIndex%>" UseSubmitBehavior="False" />
</ItemTemplate>
<FooterTemplate>
<asp:ImageButton ID="btnAdd" runat="server" CommandName="Add" ImageUrl="~/images/add.png" AlternateText="Add" UseSubmitBehavior="False"/>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
CodeBehind:
protected void gwProfit_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (ViewState["dtStartDate"] != null)
dtStartDate = (DataTable) ViewState["dtStartDate"];
if (e.CommandName.Equals("Add"))
{
TextBox txtStartDate = (TextBox)gwProfit.FooterRow.FindControl("txtNewStartDate");
TextBox txtEndDate = (TextBox)gwProfit.FooterRow.FindControl("txtNewEndDate");
TextBox txtProfitPerUnit = (TextBox)gwProfit.FooterRow.FindControl("txtNewProfitPerUnit");
if (txtEndDate.Text == "" || txtStartDate.Text == "" || txtProfitPerUnit.Text == "")
{
ScriptManager.RegisterStartupScript(this, GetType(), "alert", "alert('Please Select Start Date, End Date And Profit Per Unit.')", true);
}
else
{
dtStartDate.Rows.Add(dtStartDate.NewRow());
dtStartDate.Rows[dtStartDate.Rows.Count - 1]["CurrencyDeatailID"] = -2;
dtStartDate.Rows[dtStartDate.Rows.Count - 1]["StartDate"] = objFunc.toDate(txtStartDate.Text);
dtStartDate.Rows[dtStartDate.Rows.Count - 1]["EndDate"] = objFunc.toDate(txtEndDate.Text);
dtStartDate.Rows[dtStartDate.Rows.Count - 1]["ProfitPerUnit"] = objFunc.toDecimal(txtProfitPerUnit.Text);
if (dtStartDate.Rows.Count >= 0&&dtStartDate.Rows[0]["CurrencyDeatailID"].ToString()=="-1")
{
dtStartDate.Rows[0].Delete();
if (dtStartDate.Rows.Count > 0 && dtStartDate.Rows[0].RowState == DataRowState.Deleted)
dtStartDate.Rows.RemoveAt(0);
}
ViewState["dtStartDate"] = dtStartDate;
Profit_LoadGrid();
}
}
else if (e.CommandName.Equals("Delete"))
{
int index = objFunc.toInt(e.CommandArgument.ToString());
GridViewRow gvr = (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer);
int RemoveAt = gvr.RowIndex;
DataTable dt = new DataTable();
dt = (DataTable)ViewState["dtStartDate"];
dt.Rows.RemoveAt(RemoveAt);
dt.AcceptChanges();
ViewState["dtStartDate"] = dt;
Profit_LoadGrid();
}
}
It would be easy
Activate "AllowPaging" in your GridView.
Make Paging row invisible.
In every click of an icon increase "PageSize" for expanding or click of another icon decrease "PageSize" for collapsing.
<asp:Panel ID="pnlGrdShift" runat="server" ScrollBars="Auto" Width="900px" Height="520px" CssClass="srcColor">
<cc1:GridView ID="gvShift" runat="server" AutoGenerateColumns="False" AllowSorting="True"
CssClass="grid"
OnDataBound="gvShift_DataBound"
DataSourceID="odsShiftDetails"
AllowPaging="True"
ShowFooter="false"
onrowcancelingedit="gvShift_RowCancelingEdit"
onrowcommand="gvShift_RowCommand"
onrowdeleting="gvShift_RowDeleting"
onrowediting="gvShift_RowEditing"
onrowupdating="gvShift_RowUpdating"
OnSelectedIndexChanged="gvShift_SelectedIndexChanged"
OnRowDataBound="gvShift_RowDataBound">
<AlternatingRowStyle CssClass="altrowstyle" />
<HeaderStyle CssClass="headerstyle" />
<RowStyle CssClass="rowstyle" Wrap="false" />
<EmptyDataRowStyle BackColor="#edf5ff" Height="300px" VerticalAlign="Middle" HorizontalAlign="Center" />
<EmptyDataTemplate >
No Records Found
</EmptyDataTemplate>
<Columns>
<asp:TemplateField HeaderText="E Code" SortExpression="userecode" HeaderStyle-Font-Bold="true" HeaderStyle-Font-Names="Calibre" HeaderStyle-ForeColor="White">
<ItemTemplate>
<asp:Label ID="lblUserECode" runat="server" Text='<%#Eval("userecode") %>' CssClass="GridContent" />
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblEditUserECode" runat="server" Text='<%#Eval("userecode") %>' style="width:50px;" CssClass="GridContent" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="User Name" SortExpression="username" HeaderStyle-Font-Bold="true" HeaderStyle-Font-Names="Calibre" HeaderStyle-ForeColor="White">
<ItemTemplate>
<asp:Label ID="lblUserName" runat="server" Text='<%#Eval("username") %>' CssClass="GridContent" />
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblEditUserName" runat="server" Text='<%#Eval("username") %>' style="width:100px;" CssClass="GridContent"/>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Shift Start Time" SortExpression="ShiftStartTime" HeaderStyle-Font-Bold="true" HeaderStyle-Font-Names="Calibre" HeaderStyle-ForeColor="White">
<ItemTemplate>
<asp:Label ID="lblShiftStartTime" runat="server" Text='<%#Eval("ShiftStartTime") %>' CssClass="GridContent"/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="ddlShiftStartTime" runat="server" Text='<%#Eval("ShiftStartTime") %>' style="width:65px;" CssClass="GridContent" />
<asp:RegularExpressionValidator ID="RegularExpValidatorddlShiftStartTime" runat="server" ControlToValidate="ddlShiftStartTime" ValidationExpression="^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$" ErrorMessage="*" Font-Bold="true" ForeColor="Red" ToolTip="Must be in HH:MM" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Shift End Time" SortExpression="ShiftEndTime" HeaderStyle-Font-Bold="true" HeaderStyle-Font-Names="Calibre" HeaderStyle-ForeColor="White">
<ItemTemplate>
<asp:Label ID="lblShiftEndTime" runat="server" Text='<%#Eval("ShiftEndTime") %>' CssClass="GridContent" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="ddlShiftEndTime" runat="server" Text='<%#Eval("ShiftEndTime") %>' style="width:65px;" CssClass="GridContent" />
<asp:RegularExpressionValidator ID="RegularExpValidatorddlShiftEndTime" runat="server" ControlToValidate="ddlShiftEndTime" ValidationExpression="^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$" ErrorMessage="*" Font-Bold="true" ForeColor="Red" ToolTip="Must be in HH:MM" />
</EditItemTemplate>
</asp:TemplateField>
<%--<asp:BoundField DataField="ShiftEndTIme" HeaderText="Shift End Time" SortExpression="ShiftEndTIme"/>--%>
<asp:TemplateField HeaderText="Saturday Shift Start Time" SortExpression="WeekendShiftStartTime" HeaderStyle-Font-Bold="true" HeaderStyle-Font-Names="Calibre" HeaderStyle-ForeColor="White">
<ItemTemplate>
<asp:Label ID="lblWeekendShiftStartTime" runat="server" Text='<%#Eval("WeekendShiftStartTime") %>' CssClass="GridContent" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="ddlWeekendShiftStartTime" runat="server" Text='<%#Eval("WeekendShiftStartTime") %>' style="width:65px;" CssClass="GridContent" />
<asp:RegularExpressionValidator ID="RegularExpValidatorddlWeekendShiftStartTime" runat="server" ControlToValidate="ddlWeekendShiftStartTime" ValidationExpression="^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$" ErrorMessage="*" Font-Bold="true" ForeColor="Red" ToolTip="Must be in HH:MM" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Saturday Shift End Time" SortExpression="weekendshiftendtime" HeaderStyle-Font-Bold="true" HeaderStyle-Font-Names="Calibre" HeaderStyle-ForeColor="White">
<ItemTemplate>
<asp:Label ID="lblWeekendShiftEndTime" runat="server" Text='<%#Eval("weekendshiftendtime") %>' CssClass="GridContent"/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="ddlWeekendShiftEndTime" runat="server" Text='<%#Eval("weekendshiftendtime") %>' style="width:65px;" CssClass="GridContent" />
<asp:RegularExpressionValidator ID="RegularExpValidatorddlWeekendShiftEndTime" runat="server" ControlToValidate="ddlWeekendShiftEndTime" ValidationExpression="^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$" ErrorMessage="*" Font-Bold="true" ForeColor="Red" ToolTip="Must be in HH:MM" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False" >
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update" ForeColor="White"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" ForeColor="White"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" ForeColor="White"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerTemplate >
<table width="100%" >
<tr>
<td style="text-align: left">
Page Size:
<asp:DropDownList ID="ddPageSize" runat="server" EnableViewState="true" OnSelectedIndexChanged="ddPageSize_SelectedIndexChanged" AutoPostBack="true" style="width:50px;">
<asp:ListItem Text="10" ></asp:ListItem>
<asp:ListItem Text="20" ></asp:ListItem>
<asp:ListItem Text="30" ></asp:ListItem>
<asp:ListItem Text="40" ></asp:ListItem>
<asp:ListItem Text="50" ></asp:ListItem>
</asp:DropDownList>
</td>
<td style="text-align: right">
<asp:Label ID="lblPageCount" runat="server"></asp:Label>
</td>
</tr>
</table>
</PagerTemplate>
</cc1:GridView>
</asp:Panel></td></tr>
</table>
<div style="margin-top:5px" class="PagerGrid">
<asp:DataPager ID="pager" runat="server" PagedControlID="gvShift">
<Fields>
<asp:NextPreviousPagerField FirstPageText="<<" LastPageText=">>"
NextPageText=">" PreviousPageText="<" ShowFirstPageButton="True"
ShowNextPageButton="False" ButtonCssClass="datapager" />
<asp:NumericPagerField ButtonCount="10" NumericButtonCssClass="datapager" CurrentPageLabelCssClass="datapager" />
<asp:NextPreviousPagerField LastPageText=">>" NextPageText=">"
ShowLastPageButton="True" ShowPreviousPageButton="False" ButtonCssClass="datapager" />
</Fields>
</asp:DataPager>
</div>
<br />
<asp:ObjectDataSource ID="odsShiftDetails" runat="server"
SelectMethod="GetShiftInfoSortedPage" TypeName="EQ.DAL.ShiftInfoDB"
EnablePaging="True" SelectCountMethod="GetShiftInfoCount"
SortParameterName="sortExpression">
<SelectParameters>
<asp:ControlParameter ControlID="hfSearchCriteria" Name="searchCriteria" Direction="Input" />
</SelectParameters>
</asp:ObjectDataSource>
Code behind for Row Updation is:-
protected void gvShift_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
TextBox txtShiftStartTime = (TextBox)gvShift.Rows[e.RowIndex].FindControl("ddlShiftStartTime");
TextBox txtShiftEndTime = (TextBox)gvShift.Rows[e.RowIndex].FindControl("ddlShiftEndTime");
TextBox txtWeekendShiftStartTime = (TextBox)gvShift.Rows[e.RowIndex].FindControl("ddlWeekendShiftStartTime");
TextBox txtWeekendShiftEndTime = (TextBox)gvShift.Rows[e.RowIndex].FindControl("ddlWeekendShiftEndTime");
Label lblUserecode = (Label)gvShift.Rows[e.RowIndex].FindControl("lblEditUserECode");
string userecode = lblUserecode.Text.ToString();
string _ShiftStart = txtShiftStartTime.Text.ToString();
string _ShiftEnd = txtShiftEndTime.Text.ToString();
string _WeekendShiftStart = txtWeekendShiftStartTime.Text.ToString();
string _WeekendShiftend = txtWeekendShiftEndTime.Text.ToString();
EmployeeQuotientCL.Entities.ConfigurationVariables _configVariables = new ConfigurationVariables();
string databaseConnectionString = _configVariables.ConnectionString;
SqlConnection sqlConnection = null;
if (((databaseConnectionString + string.Empty) != string.Empty))
{
DBConnect dbConnect = new DBConnect(_configVariables.ConnectionString);
sqlConnection = dbConnect.SQLConnection;
SqlCommand cmd = new SqlCommand();
cmd.Connection = sqlConnection;
cmd.CommandText = "UPDATE UserInfo SET ShiftStartTime ='" + _ShiftStart + "',ShiftEndTime='" + _ShiftEnd.ToString() + "',Weekendshiftstarttime='" + _WeekendShiftStart.ToString() + "',Weekendshiftendtime='" + _WeekendShiftend.ToString() + "' WHERE UserECode=" + userecode.ToString();
sqlConnection.Open();
cmd.ExecuteNonQuery();
gvShift.DataSource = null;
gvShift.DataBind();
sqlConnection.Close();
}
}
catch (Exception ex)
{
}
}
While Updating the Rows in grid , I am getting the below error message.
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: >Updating is not supported by ObjectDataSource 'odsShiftDetails' unless the UpdateMethod is >specified.
Guide me how to fix this error. Thanks in advance.
You need to add an update method to your gridview. Look at this tutorial: Gridview ObjectdataSource
I have a Page which has a 2 level web tab . The Content tabs FIXED and VARIABLE in turn has a web tab. This web tab is loaded with a User control which has a gridview.
My problem is the textboxes in the Gridview are not cleared on going from one sub tab to next sub tab . I tried all possible methods :
1.Bind grid to null ( datasource and DatasoruceId )
2. grid dispose
3. grid columns clear
No luck !!!.. HELP!!!
Note : I am modifying the data in the textboxes from javascript.
<ig:Webtab id="wi" runat="server" width="938px" displaymode="Scrollable" meta:resourcekey="wtabInvestmentTypeResource1">
<ClientEvents SelectedIndexChanging="webTab_SelectedIndexChanging" />
<AutoPostBackFlags SelectedIndexChanged="On" />
<Tabs>
<ig:ContentTabItem runat="server" Text="Variable Investment Type" meta:resourcekey="ContentTabItemResource1">
<Template>
<div class="clear vspacesmall hspacenarrow">
</div>
<ig:WebTab ID="wv" runat="server" Width="908px" DisplayMode="Scrollable" ClientIDMode="Static"
meta:resourcekey="wtabVariableResource1">
<ClientEvents SelectedIndexChanging="webTab_SelectedIndexChanging" />
<AutoPostBackFlags SelectedIndexChanged="On" />
</ig:WebTab>
</Template>
</ig:ContentTabItem>
<ig:ContentTabItem runat="server" Text="Fixed Investment Type" meta:resourcekey="ContentTabItemResource2">
<Template>
<div class="clear vspacesmall hspacenarrow">
</div>
<ig:WebTab ID="wf" runat="server" Width="908px" DisplayMode="Scrollable" class="tabs"
meta:resourcekey="wtabFixedResource1">
<ClientEvents SelectedIndexChanging="webTab_SelectedIndexChanging" />
<AutoPostBackFlags SelectedIndexChanged="On" />
</ig:WebTab>
The web tab loads a user control which has the following gridview :
<div class="clear vspacesmall gridtablearea scrollPanel-horizontal Contol-Max-Height">
<asp:UpdatePanel ID="upBuyMultipleGetDiscount" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="gvInvestmentDetails" runat="server" OnRowDataBound="gvInvestmentDetails_RowDataBound"
TabIndex="5" AutoGenerateColumns="False" CssClass="gridtable scrollPanel-horizontal" Width="100%" meta:resourcekey="gvInvestmentDetails_DefaultResource1"
EnableViewState="true" ViewStateMode="Enabled" ShowFooter="true" OnRowCommand="gvInvestmentDetails_Row_Command">
<Columns>
<asp:BoundField DataField="InvestmentTypeId" />
<asp:BoundField DataField="CustomerCombinationId" />
<asp:BoundField DataField="ProductId" />
<asp:TemplateField HeaderText="Account" ItemStyle-Width="100px" meta:resourcekey="Account">
<ItemTemplate>
<asp:Label ID="lblAccountName" runat="server" Text='<%# Eval("CustomerCombinationName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Products" ItemStyle-Width="200px" meta:resourcekey="Products">
<ItemTemplate>
<asp:Label ID="lblProductName" runat="server" Text='<%# Eval("ProductName") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblTotal" CssClass="fRight boldText" ForeColor="#656565" runat="server" Text='TOTAL :' meta:resourcekey="lblTotal"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Phase Investment Amount" meta:resourcekey="PhaseInvestmentAmount" >
<ItemTemplate>
<asp:Repeater ID="rptrPhases" runat="server" ClientIDMode="Static" OnDataBinding="rptrPhases_OnDataBinding">
<ItemTemplate>
<div style="float: left; padding: 4px;">
<table id="PhaseDetails">
<tr>
<td>
<tr>
<asp:Label ID="lblPhaseID" runat="server" Text='<%# Eval("PhaseID") %>' Visible="False"></asp:Label>
<asp:Label ID="lblPhaseName" Class="vspacesmall" runat="server" Text='<%# Eval("PhaseName") %>' ></asp:Label><br />
<asp:TextBox ID="txtPhaseAmount" runat="server" Text='<%# Eval("PhaseAmount", "{0:F2}") %>' CssClass="tar"
ClientIDMode="Static" Width="80px" MaxLength="27" onpaste="return false;" ViewStateMode="Enabled"
meta:resourcekey="txtPhaseAmount"></asp:TextBox>
</tr>
<tr>
<asp:Label ID="lblUsageAmount" runat="server" Visible="false" Text='<%# Eval("PhaseUpdateAmount", "{0:F2}") %>'></asp:Label>
</tr>
</td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
<FooterTemplate>
<asp:Repeater ID="rptTotalAmount" runat="server" ClientIDMode="Static">
<ItemTemplate>
<div style="float: left; padding: 4px;">
<table>
<tr>
<td>
<asp:TextBox ID="txtPhaseTotal" Text='<%# Eval("PhaseAmount", "{0:F2}") %>' Width="80px" CssClass="tar boldText"
ForeColor="#656565" runat="server" ViewStateMode="Enabled" ClientIdMode="Static" autocomplete="off" ></asp:TextBox>
</td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:Repeater>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Roles" ItemStyle-Width="150px" meta:resourcekey="Roles">
<ItemTemplate>
<asp:CheckBoxList ID="chckRoleList" runat="server" DataTextField="RoleName"
DataValueField="RoleId" EnableViewState="true" ViewStateMode="Enabled" onclick="checkBoxLstChanged(this.id,'chkSelectAll');SetIsChanged('1');">
</asp:CheckBoxList>
<asp:RadioButtonList ID="rdbRoleList" runat="server" DataTextField="RoleName"
DataValueField="RoleId" EnableViewState="true" ViewStateMode="Enabled">
</asp:RadioButtonList>
</ItemTemplate>
<FooterTemplate>
<asp:CheckBox ID="chckSelectAll" runat="server" Text="Select All" onclick="setAllCheckBoxes('chckRoleList',this);SetIsChanged('1');" meta:resourcekey="chckSelectAll">
</asp:CheckBox>
<br>
<asp:Button ID="btnRemove" runat="server" CssClass="btnStyle fLeft" Text="Remove" OnClientClick="return ValidateRemoveRoles('gvInvestmentDetails')"
CommandName="RemoveRoles" CommandArgument='<%# Container.DataItemIndex %>'
meta:resourcekey="btnRemove" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="InvestmentAmount" meta:resourcekey="InvestmentAmount">
<ItemTemplate>
<asp:TextBox ID="txtInvAmt" Width="80px" runat="server" Text='<%# Eval("InvestmentAmount","{0:F2}") %>'
ClientIdMode="Static" ViewStateMode="Enabled" CssClass="fRight tar boldText" ></asp:TextBox >
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtTotalInvestment" ClientIdMode="Static" Width="80px" ViewStateMode="Enabled" CssClass="fRight tar boldText " ForeColor="#656565" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:BoundField DataField="RecordStatus" />
</Columns>
<%-- <FooterStyle HorizontalAlign="Left" CssClass="boldText" ForeColor="#656565" />--%>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
The back end code for loading the USer control :
private void LoadInvestmentDetails(int investmentTypeId, WebTab currentWebTab, int tabIndex)
{
Panel panel = GetPanelToBeLoaded(investmentTypeId);
if (currentWebTab.Tabs[tabIndex].Controls.Count == 0)
{
currentWebTab.Tabs[tabIndex].Controls.Add(panel);
budgetDetailsControl.Initialize(investmentTypeId);
budgetDetailsControl.InvestmentDetailsSaved += new ProjectInvestmentDetailsSavedEventHandler(BudgetDetailsControl_BudgetDetailsSaved);
PreviouslyLoadedTab = int.Parse(currentWebTab.Tabs[currentWebTab.SelectedIndex].UserControlUrl);
}
// other code
}
private Panel GetPanelToBeLoaded(int investmentTypeId)
{
System.Web.UI.Control userControl = GetInvestmentDetailsUserControlUrl();
Panel panel = new Panel();
panel.Controls.Add(userControl);
budgetDetailsControl = (IProjectInvestmentDetailsControl)userControl;
budgetDetailsControl.InvestmentTypeID = investmentTypeId;
return panel;
}
private System.Web.UI.Control GetInvestmentDetailsUserControlUrl()
{
return LoadControl(ProjectCommonKeys.URL_PROJECT_BUDGET_DETAILS);
}
The Usercontrol implments the IprojectInvestmentDetails interface and the initalize function of the UC is called first for the binding etc
I figured out the problem. Each user control bound to the sub tab shud be given a unique Id..or else even if we bind new data the data from the earlier instance will persist.
.
private Panel GetPanelToBeLoaded(int investmentTypeId)
{
System.Web.UI.Control userControl = GetInvestmentDetailsUserControlUrl();
**userControl.ID = investmentTypeId.ToString();**
Panel panel = new Panel();
panel.Controls.Add(userControl);
projectInvestmentDetailsControl = (IProjectInvestmentDetailsControl)userControl;
projectInvestmentDetailsControl.InvestmentTypeID = investmentTypeId;
projectInvestmentDetailsControl.UserContext = userContext;
projectInvestmentDetailsControl.PlanningWizardDataManager = PlanningWizardDataManager;
projectInvestmentDetailsControl.PlanningServiceWrapper = PlanningServiceWrapper;
return panel;
}`
Thanks fr the help...
I Have the below Asp.net Code:
the problem is that When Timer Tick Every 30 Second and GridView Filled the javascript code is not executed !! and Sound is not played.
I have also tried SoundPlayer Class but is not working on the Server Side can anyone provide me with a solution ?
<%# Page Language="C#" AutoEventWireup="true" CodeFile="OrdersPage.aspx.cs" Inherits="Orders_" Async="true" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Gazar | Orders Page</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<link rel="Stylesheet" href="StyleSheet.css" />
<script type="text/javascript">
function ShowProgress() {
document.getElementById('UpdateProgress1').style.display = "inline";
}
</script>
</head>
<body>
<form id="form1" class="center_it" runat="server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" EnablePageMethods="true" runat="server"></asp:ToolkitScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<table class="MainTable">
<tr>
<td style="text-align: left;" colspan="2">
<img id="Img2" src="~/images/gazzarlogo.png" alt="GazarBanner" runat="server" class="BannerImage" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="30pt" ForeColor="White"
Text="الطلبـــــات"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="History" CssClass="Buttons" />
</td>
<td>
<asp:Button ID="Exit" Text="خروج" runat="server" OnClick="Exit_Click" CssClass="Buttons" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:GridView ID="GridViewOrders" runat="server" Style="margin-left: auto; margin-right: auto;"
OnRowDataBound="GridViewOrders_RowDataBound" PageSize="30" BackColor="White"
BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="0px" CaptionAlign="Top"
CellPadding="4" ForeColor="Black" HorizontalAlign="Center" EnableModelValidation="True"
GridLines="Vertical" Width="1100px" Font-Names="Tahoma" Font-Size="10pt" Font-Bold="False"
OnRowCommand="GridViewOrders_RowCommand" AutoGenerateColumns="False">
<RowStyle BackColor="#F7F7DE" Wrap="True" />
<AlternatingRowStyle BackColor="White" />
<FooterStyle BackColor="#CCCC99" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:TemplateField HeaderText="Open" ItemStyle-Width="60px">
<ItemTemplate>
<asp:Button ID="ApproveBtn" Text="Open" Width="60" Height="30" runat="server" OnClientClick="ShowProgress()" />
</ItemTemplate>
<ItemStyle Width="70px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="ID" ItemStyle-Width="70px">
<ItemTemplate>
<asp:Label ID="OrderID" CommandName="Select" runat="server" Text='<% #DataBinder.Eval(Container.DataItem, "ID") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="70px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Name" ItemStyle-Width="150px">
<ItemTemplate>
<asp:Label ID="Name" CommandName="Select" runat="server" Text='<% #DataBinder.Eval(Container.DataItem, "Name") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="150px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Address" ItemStyle-Width="300px">
<ItemTemplate>
<asp:Label ID="Address" CommandName="Select" runat="server" Text='<% #DataBinder.Eval(Container.DataItem, "Address") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="300px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Number" ItemStyle-Width="100px">
<ItemTemplate>
<asp:Label ID="Number" CommandName="Select" runat="server" Text='<% #DataBinder.Eval(Container.DataItem, "Number") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="100px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Sent Date" ItemStyle-Width="100px">
<ItemTemplate>
<asp:Label ID="SentDate" CommandName="Select" runat="server" Text='<% #DataBinder.Eval(Container.DataItem, "Sent Date") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="100px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Recieved Date" ItemStyle-Width="100px">
<ItemTemplate>
<asp:Label ID="RecievedDate" CommandName="Select" runat="server" Text='<% #DataBinder.Eval(Container.DataItem, "Recieved Date") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="100px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="# Success" ItemStyle-Width="50px">
<ItemTemplate>
<asp:Label ID="SuccessNo" CommandName="Select" runat="server" Text='<% #DataBinder.Eval(Container.DataItem, "# Success") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="50px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="# Fake" ItemStyle-Width="50px">
<ItemTemplate>
<asp:Label ID="FakeNo" CommandName="Select" runat="server" Text='<% #DataBinder.Eval(Container.DataItem, "# Fake") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="50px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Restaurant" ItemStyle-Width="50px">
<ItemTemplate>
<asp:Label ID="Restaurant" CommandName="Select" runat="server" Text='<% #DataBinder.Eval(Container.DataItem, "Restaurant") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="50px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Branch" ItemStyle-Width="50px">
<ItemTemplate>
<asp:Label ID="Branch" CommandName="Select" runat="server" Text='<% #DataBinder.Eval(Container.DataItem, "Branch") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="50px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
<div class="container">
<div class="LoadingDiv">
<span class="LoadingLabel">Check Orders ...</span>
<img class="LoadingImg" src="Images/ajax-loader.gif" alt="Loading ..." />
</div>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
<asp:Timer ID="Timer1" runat="server" Interval="30000" OnTick="Timer1_Tick" />
</form>
</body>
</html>
and code behind is:
protected void Timer1_Tick(object sender, EventArgs e)
{
orderDB.LogState("Time Tick");
if (Session["UserID"] != null)
{
orderDB.LogState("Session Alive");
FillDataGrid(int.Parse(Session["UserID"].ToString()));
orderDB.LogState("End fill Grid View");
}
else
{
Response.Redirect("~/login.aspx");
}
}
private void FillDataGrid(int UserID)
{
Orders = orderDB.GetOrdersByUser(UserID);
orderDB.LogState("Select: " + DateTime.Now.ToString() + "\t" + Request.UserHostAddress + "\t" + Session.SessionID + "\t" + Session["UserID"].ToString());
if (Orders == null)
Response.Redirect("~/login.aspx");
DataTable Table = new DataTable();
Table.Columns.Add("ID", System.Type.GetType("System.String"));
Table.Columns.Add("Name", System.Type.GetType("System.String"));
Table.Columns.Add("Address", System.Type.GetType("System.String"));
Table.Columns.Add("Number", System.Type.GetType("System.String"));
Table.Columns.Add("Sent Date", System.Type.GetType("System.String"));
Table.Columns.Add("Recieved Date", System.Type.GetType("System.String"));
Table.Columns.Add("# Success", System.Type.GetType("System.String"));
Table.Columns.Add("# Fake", System.Type.GetType("System.String"));
Table.Columns.Add("Restaurant", System.Type.GetType("System.String"));
Table.Columns.Add("Branch", System.Type.GetType("System.String"));
for (int i = 0; i < Orders.Count; i++)
{
object[] myRow = new object[10];
myRow[0] = Orders[i].GetId();
myRow[1] = Orders[i].GetOwner();
myRow[2] = Orders[i].GetAddress().getAllAddress();
myRow[3] = Orders[i].GetPhoneNumber();
myRow[4] = Orders[i].GetOriginalTime().ToString();
myRow[5] = Orders[i].GetTime().ToString();
myRow[6] = Orders[i].NoOfSuccess; //success Orders;
myRow[7] = Orders[i].NoOfFake; //fake Orders
myRow[8] = Orders[i].GetResName();
myRow[9] = Orders[i].GetBranchName();
Table.Rows.Add(myRow);
}
orderDB.LogState("Table Rows Count: " + Table.Rows.Count);
GridViewOrders.DataSource = Table;
GridViewOrders.DataBind();
string sSelectedAudio = Server.MapPath("home.wav");
if (GridViewOrders.Rows.Count != 0)
{
playSound(sSelectedAudio);
orderDB.LogState("Sound Played: " + GridViewOrders.Rows.Count);
}
else
{
orderDB.LogState("Empty Grid View: " + GridViewOrders.Rows.Count);
}
}
private void playSound(string path)
{
string PlaySound = "<embed src=\"" + path + "\" autostart=\"true\" hidden=\"true\"></embed>";
Response.Write(PlaySound);
}
It could be the Response.Write that's causing the issue. Try using a placeholder control then adding a HtmlGenericControl to it with the markup for the embed tag i.e.
HtmlGenericControl sound = new HtmlGenericControl("<embed src=\"" + path + "\"
autostart=\"true\" hidden=\"true\"></embed>");
ucPlaceHolder.Controls.Add(sound);
Make sure the placeholder control is withing the ContentTemplate of the UpdatePanel that you are using