Nested Update panel update child problem [duplicate] - c#

I am having a nested update panel
something like this
<asp:UpdatePanel ID="DetailsUpdatePanel" runat="server" Visible="false" UpdateMode="Conditional" >
<ContentTemplate>
<div><ajaxToolkit:AsyncFileUpload runat="server" ID="BrochureUpload" Width="400px"
OnClientUploadError="BrochureuploadError"
OnClientUploadStarted="BrochureStartUpload"
OnClientUploadComplete="BrochureUploadComplete"
CompleteBackColor="Lime" UploaderStyle="Modern"
ErrorBackColor="Red" ClientIDMode="AutoID"
ThrobberID="Throbber"
UploadingBackColor="#66CCFF"
onuploadedcomplete="BrochureUpload_UploadedComplete"/>
<asp:Label ID="Label1" runat="server" Style="display: none">
<asp:Image runat="server" ID="Image1" ImageUrl="~/Images/uploading.gif" />
</asp:Label>
<asp:Label ID="brochurelblstatus" runat="server" Style="font-family: Arial; font-size: small;"></asp:Label></div>
<div><asp:UpdatePanel runat="server" ID="child" UpdateMode="Conditional" >
<ContentTemplate>
<div>
<asp:GridView ID=GridView2" runat="server" AllowPaging="true" AutoGenerateColumns="false" CellPadding="0" CellSpacing="1" DataKeyNames="ArticleId">
<Columns>
<asp:BoundField DataField="ArticleId" HeaderText="ArticleId" ReadOnly="True" HeaderStyle-CssClass="td1" />
<asp:BoundField DataField="FileName" HeaderText="FileName" ReadOnly="True" HeaderStyle-CssClass="td2" />
<asp:TemplateField HeaderText="BrochureUrl">
<ItemTemplate>
<asp:HyperLink ID="lnkEPhoto" runat="server" BorderWidth="2px" NavigateUrl='<%# GetUrl(Eval("ArticleId"),Eval("FileName")) %>'
Target="_blank"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnRemove" runat="server" text="Delete" CommandName="Delete" CausesValidation="False" OnClientClick="DeleteOrNo()">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</ContentTemplate>
</asp:UpdatePanel></div>
</ContentTemplate>
</updatePanel>
CodeBehind:
protected void BrochureUpload_UploadedComplete(object sender, AsyncFileUploadEventArgs e)
{
if(BrochureUpload.HasFile)
{
if(BrochureUpload.PostedFile.ContentLength<=3670016 )
{
var brochurePath = MapPath("~/") + Path.GetFileName(e.filename);
BrochureUpload.SaveAs(brochurePath);
using (var dataContext = new NewsStandAloneDataContext(Config.StandaloneNewsConnectionString))
{
var brochure = new xxx
{
Id = Convert.ToInt32(GridView1.SelectedValue),
FileName = Path.GetFileName(e.filename),
RecordCreated = DateTime.Now
};
dataContext.xxx.InsertOnSubmit(brochure);
dataContext.SubmitChanges();
}
bindGridView();//I have code to bind gridview
Child.Update();
}
}
}
protected void bindBrochureGridView()
{
using (var dataContext = new NewsStandAloneDataContext(Config.StandaloneNewsConnectionString))
{
var brochureList = (from brochure in dataContext.xxx
where brochure.ArticleId == Convert.ToInt32(GridView2.SelectedValue)
select new ArcticleBrochure
{
ArticleId = brochure.ArticleId.ToString(),
FileName = brochure.FileName
}).ToList();
GridView1.DataSource = brochureList;
GridView1.DataBind();
}
}
When I upload the file , I want the giedview which is in the child updatepanel to be updated .But it doesnt work Any ideas?????
thanks in advance

Call child.Update(); in BrochureUpload_UploadedComplete event.
protected void BrochureUpload_UploadedComplete(object sender, AsyncFileUploadEventArgs e)
{
....................
....................
bindGridView();//I have code to bind gridview
child.Update();
}

When file upload is complete then call Child.Update() method of UpdatePanel which contain gridview. You need to do that because you set UpdateMode="Conditional" in this case you have to manually update it in code.

ChildrenAsTriggers="True" in your updatepanel.

Related

Get textbox.text from nested gridview

I have a parent gridview with a child gridview
<!-- Parent -->
<asp:GridView ID="gvParent" runat="server" AutoGenerateColumns="false" Width="100%" CssClass="Grid"
DataKeyNames="SupplierReference" OnRowDataBound="gvParent_OnRowDataBound" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<img alt = "" style="cursor: pointer" src="images/plus.png" />
<asp:Panel ID="pnlOrders" runat="server" Style="display: none">
<!-- Child -->
<asp:GridView ID="gvChild" runat="server" AutoGenerateColumns="false" CssClass = "ChildGrid"
ShowFooter = "true" OnRowDataBound="gvChild_OnRowDataBound">
<Columns>
<asp:TemplateField HeaderText="Qty" ItemStyle-Width="100px">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("Qty")%>' />
</ItemTemplate>
</asp:TemplateField >
</Columns>
</asp:GridView>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkSelectQtys" runat="server"
CommandArgument = '<%# Eval("SupplierReference")%>' CommandName="SelectQtys"
OnClientClick = "return confirm('Add these materials to this task?')"
Text = "Add" OnClick="getQty" ></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I am trying to have a textbox that the user can alter the value and when they click add I want to be able to pull that text into the C# code and work with it.
I cant get it into my C# code.
protected void getQty(object sender, EventArgs e)
{
//After clicking "add"....
//Do something here to get text from each TextBox1 in the Child gridview
}
Someone please help before I lose what little hair I have left...
protected void getQty(object sender, EventArgs e)
{
//After clicking "add"....
string s;
for(i=0; i < gvChild.Rows.Count; i++)
{
s = ((TextBox)gvChild.Rows[i].FindControl("TextBox1")).Text;
}
//Do what you want to with this string
}

Display nested gridview

I have a nested GridView with 4 levels,
when i click in "+" to show child GridView i make request to database to download data of current row, every thing work well for me, the only problem i have is in design, all the child GridView display in column of its parent GridView
this is how it looks:
Parent GridView
First Child gridView
here is my aspx code:
<asp:UpdatePanel ID="upNestedGridView" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="gvCostCenters" runat="server" ....>
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="imgShowAccountingPlan" runat="server" OnClick="Show_Hide_AccountingPlansGrid" .../>
<asp:Panel ID="pnlAccountingPlan" runat="server" Visible="false" Style="position: relative">
<asp:GridView ID="gvAccountingPlans" runat="server" AutoGenerateColumns="false"....">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="imgShowPrograms" runat="server" OnClick="Show_Hide_ProgramsGrid" .../>
<asp:Panel ID="pnlPrograms" runat="server" Visible="false" Style="position: relative">
<asp:GridView ID="gvPrograms" runat="server" AutoGenerateColumns="false" ...>
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="imgShowProjects" runat="server" OnClick="Show_Hide_ProjectsGrid" ..../>
<asp:Panel ID="pnlProjects" runat="server" Visible="false" Style="position: relative">
<asp:GridView ID="gvProject" runat="server" ....>
.....
</asp:GridView>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Label" HeaderText="البند " ItemStyle-HorizontalAlign="Right" />
....
</Columns>
</asp:GridView>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="NumAccountingPlan" HeaderText="الخطة المحاسبية " ItemStyle-HorizontalAlign="Right" />
...
</Columns>
</asp:GridView>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
...
<asp:BoundField DataField="OperatingExpenses" HeaderText="المصروفات التشغيلية" DataFormatString="{0:#,##0.00;(#,##0.00);0}" />
</Columns>
</asp:GridView>
my jquery code:
<script type="text/javascript">
$(function () {
$("[src*=minus]").each(function () {
$(this).closest("tr").after("<tr><td></td><td colspan = '999'>" + $(this).next().html() + "</td></tr>");
$(this).next().remove()
});
});
</script>
My code C#:
protected void Show_Hide_AccountingPlansGrid(object sender, EventArgs e)
{
try
{
ServiceClass service = new ServiceClass();
ImageButton imgShowHide = (sender as ImageButton);
GridViewRow row = (imgShowHide.NamingContainer as GridViewRow);
if (imgShowHide.CommandArgument == "Show")
{
_budget = service.GetBudgetById(int.Parse(hfIdBudget.Value));
row.FindControl("pnlAccountingPlan").Visible = true;
imgShowHide.CommandArgument = "Hide";
imgShowHide.ImageUrl = "/Content/img/minus.gif";
string idCostCenter = gvCostCenters.DataKeys[row.RowIndex].Value.ToString();
GridView gvAccountingPlans = row.FindControl("gvAccountingPlans") as GridView;
//gvAccountingPlans.ToolTip = costCenterId;
gvAccountingPlans.DataSource = AccountingPlanData(int.Parse(hfIdUser.Value), int.Parse(hfIdBudget.Value), int.Parse(idCostCenter));
gvAccountingPlans.DataBind();
}
else
{
row.FindControl("pnlAccountingPlan").Visible = false;
imgShowHide.CommandArgument = "Show";
imgShowHide.ImageUrl = "/Content/img/plus.gif";
}
}
catch (Exception ex) { GlobalHelpers.Trace(ex); }
}
I notice that when i delete the UpdatePanel the first child GridView display well, but the others no.
How can i do to display all childs GridView well?
I'm sorry for my bad english
Code asp:
<asp:UpdatePanel ID="upNestedGridView" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="gvCostCenters" runat="server" AutoGenerateColumns="false" ....>
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="imgShowAccountingPlan" runat="server" OnClick="Show_Hide_AccountingPlansGrid" ImageUrl="/Content/img/plus.gif" CommandArgument="Show" />
</ItemTemplate>
</asp:TemplateField>
....
<asp:TemplateField>
<ItemTemplate>
<tr visible="false" runat="server" id="trAccountingPlan">
<td visible="false" runat="server" id="tdAccountingPlan2"></td>
<td colspan="999" visible="false" runat="server" id="tdAccountingPlan">
<asp:GridView ID="gvAccountingPlans" runat="server" ....>
<Columns>
.....
</Columns>
</asp:GridView>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
Code C#:
protected void Show_Hide_AccountingPlansGrid(object sender, EventArgs e)
{
try
{
ImageButton imgShowHide = (sender as ImageButton);
GridViewRow row = (imgShowHide.NamingContainer as GridViewRow);
if (imgShowHide.CommandArgument == "Show")
{
...
imgShowHide.CommandArgument = "Hide";
imgShowHide.ImageUrl = "/Content/img/minus.gif";
row.FindControl("trAccountingPlan").Visible = true;
HtmlTableCell tdAccountingPlan = (HtmlTableCell)row.FindControl("tdAccountingPlan");
HtmlTableCell tdAccountingPlan2 = (HtmlTableCell)row.FindControl("tdAccountingPlan2");
tdAccountingPlan2.Visible = true;
tdAccountingPlan.Visible = true;
...
}
else
{
imgShowHide.CommandArgument = "Show";
imgShowHide.ImageUrl = "/Content/img/plus.gif";
row.FindControl("trAccountingPlan").Visible = false;
HtmlTableCell tdAccountingPlan = (HtmlTableCell)row.FindControl("tdAccountingPlan");
HtmlTableCell tdAccountingPlan2 = (HtmlTableCell)row.FindControl("tdAccountingPlan2");
tdAccountingPlan2.Visible = false;
tdAccountingPlan.Visible = false;
}
}
catch (Exception ex) { GlobalHelpers.Trace(ex); }
}

Force UpdatePanel with datalist to refresh on database changed - SqlDependency

I'm using SQLDependency to catch changes in my database.
http://code.msdn.microsoft.com/How-to-use-SqlDependency-5c0da0b3
This code really works. When I'm changing something in table, event is fired.
private void RefreshWithSqlDependency()
{
iquery = from order in context.Order
where order.Client.Nickname==nickName && order.StatusId!=5
select new { Id = order.Id, Description = order.Description, OrderStatus = order.Status.Name };
notification = new ImmediateNotificationRegister<Order>(context, iquery);
notification.OnChanged += NotificationOnChanged;
}
protected void NotificationOnChanged(object sender, EventArgs e)
{
BindOrderDataList(); //this is executed
}
In BindOrderDataList I'm setting datasource of my datalist.
private void BindOrderDataList()
{
DataListOrders.DataSource = context.Order.Where(x => x.Client.Nickname == nickName && x.StatusId != 5)
.Select(x => new { Id = x.Id, Description = x.Description, OrderStatus = x.Status.Name }).ToList();
DataListOrders.DataBind();
}
Of course nothing happened. Then I put Datalist inside UpdatePanel.
<asp:UpdatePanel ID="UpdatePanelOrdersList" runat="server" UpdateMode="Conditional" OnLoad="UpdatePanelOrdersList_Load">
<ContentTemplate>
<asp:DataList ID="DataListOrders" runat="server" RepeatDirection="Horizontal" RepeatColumns="5" OnItemDataBound="DataListOrders_ItemDataBound"
CellPadding="5" Width="100%" OnItemCommand="DataListOrders_ItemCommand" EnableViewState="False">
<ItemStyle Wrap="True" HorizontalAlign="Center" VerticalAlign="Top"></ItemStyle>
<ItemTemplate>
<asp:Panel ID="Order" runat="server">
<div style="padding: 3px; border: 3px solid; border-color: #F0F0F0">
<h4>Order
<asp:Label ID="OrderId" runat="server" Text='<%# Eval("Id") %>'></asp:Label></h4>
<h5>Desc:
<asp:Label ID="Description" runat="server" Text='<%# Eval("Description") %>'></asp:Label></h5>
<h5>Status:
<asp:Label ID="OrderStatus" runat="server" Text='<%# Eval("OrderStatus") %>'></asp:Label></h5>
<br />
<asp:DataList ID="DataListOrderProducts" runat="server" RepeatDirection="Vertical" RepeatColumns="1"
OnItemDataBound="DataListOrderProducts_ItemDataBound" OnItemCommand="DataListOrderProducts_ItemCommand"
EnableViewState="False">
<ItemStyle Wrap="True"></ItemStyle>
<ItemTemplate>
<asp:Panel ID="OrderItem" runat="server">
<h6>Product:
<asp:Label ID="OrderProductId" runat="server" Text='<%# Eval("LineId") %>' CssClass="hiddencol"></asp:Label></h6>
<h6>Product:
<asp:Label ID="Product" runat="server" Text='<%# Eval("ProductName") %>'></asp:Label></h6>
<h6>Status:
<asp:Label ID="ProductStatus" runat="server" Text='<%# Eval("ProductStatus") %>'></asp:Label></h6>
<asp:LinkButton ID="ItemSubmit" runat="server" CommandName="ItemCompleted" Text="Complete" Visible="False" />
</asp:Panel>
</ItemTemplate>
</asp:DataList>
<asp:LinkButton ID="OrderSubmit" runat="server" CommandName="OrderCompleted" Text="Complete" Visible="false" />
</div>
</asp:Panel>
</ItemTemplate>
</asp:DataList>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="NotificationOnChanged" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DataListOrders" EventName="DataBinding" />
<asp:AsyncPostBackTrigger ControlID="DataListOrders" />
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
When I'm clicking this Button1 same method as in RefreshWithSqlDependency is executed (NotificationOnChanged) and this is working...
Is there any event that would force UpdatePanel to update when content in DataList changes?
I already tried delegate to raise update event in UpdatePanel...
protected void NotificationOnChanged(object sender, EventArgs e)
{
BindOrderDataList();
LongTimeTask_Delegate d = new LongTimeTask_Delegate(LongTimeTask);
IAsyncResult r = d.BeginInvoke("String", new AsyncCallback(TaskCompleted), null);
d.EndInvoke(r);
}
public delegate void LongTimeTask_Delegate(string str);
public void LongTimeTask(string str)
{
Thread.Sleep(50);
}
public void TaskCompleted(IAsyncResult r)
{
UpdatePanelOrdersList.Update();
}
but no success...
SQLDependency's events can't update updatepanel's content. You have to trigger update event with other event triggers like timer. if timer ticks then updatepanel updates contents. put your update datalist code into timer event. I'm using like that and it works.
You can trying to use timer control.
Here is the sample: http://www.dotnetheaven.com/article/auto-refresh-data-on-page-using-ajax-in-vb.net
Hope this help.

page load with child grids taking too much of time in loading the page

I have three grids - Category grid, Items grid and Sub Items Grid. I have category grid (grdCategories) and for each category there are many items which i bind to child grids (grdItems). For every item there are many sub items which i display in sub child grid (grdSubItems). Now the problem is that page takes too much of time in loading the data. My HTML Code is below:
It takes even minutes to load the data:
ASPX
<asp:GridView ID="grdCategories" runat="server" AutoGenerateColumns="false" DataKeyNames="Category"
CssClass="menu_items" OnRowDataBound="grdCategories_RowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Panel ID="pnlMealOptionsHeader" runat="server" Width="100%">
<h1>
<a id='<%# Eval("CategoryX")%>'>
<asp:Label ID="lblCategory" runat="server" Text='<%#Eval("Category") %>' Visible="false"></asp:Label>
<asp:Label ID="lblCategoryX" runat="server" Text='<%#Eval("CategoryX") %>'></asp:Label>
</a>
</h1>
</asp:Panel>
<asp:Panel runat="server" ID="pnlMealOptionsBody">
<asp:Label ID="lblCategoryXX" runat="server" CssClass="title_2" Text='<%#Eval("CategoryXX") %>'></asp:Label>
<!--Items in Category -->
<asp:GridView ID="grdItems" runat="server" AutoGenerateColumns="false" CssClass="active-grid"
DataKeyNames="Item" OnRowDataBound="grdItems_RowDataBound" ShowHeader="false" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblItem" runat="server" Text='<%#Eval("Item") %>' Visible="false"></asp:Label>
<asp:Label ID="lblItemX" CssClass="title" runat="server" Text='<%#Eval("ItemX") %>'></asp:Label>
<asp:Label ID="lblItemXX" CssClass="title" runat="server" Text='<%#Eval("ItemXX") %>' style=" font-size:smaller; font-weight:normal"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:GridView ID="grdSubItems" runat="server" AutoGenerateColumns="false" CssClass=""
DataKeyNames="SubItem" ShowHeader="false" OnRowDataBound="grdSubItems_RowDataBound">
<HeaderStyle HorizontalAlign="Left" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblItem" runat="server" Text='<%#Eval("Item") %>' Visible="false"></asp:Label>
<asp:Label ID="lblSubItem" runat="server" Text='<%#Eval("SubItem") %>' Visible="false"></asp:Label>
<asp:Label ID="lblNoofOptions" runat="server" Text='<%#Eval("NumofOptions") %>' Visible="false"></asp:Label>
<asp:Label ID="lblSubItemX" CssClass="qty" runat="server" Text='<%#Eval("SubItemX") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblPrice" runat="server" CssClass="price" Text='<%#String.Format("£{0}",Eval("SellingCost")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<!--End Items in Category -->
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<table width="900px">
<tr>
<td align="center">
<h1>
No Data Available</h1>
</td>
</tr>
</table>
</EmptyDataTemplate>
</asp:GridView>
Code Behind
Categories Gridview Bind
private void FillCategoriesGrid()
{
DataSet ds = new DataSet();
ShopCategoryMapBL bl = new ShopCategoryMapBL(SessionContext.SystemUser);
bl.FetchForShop(ds, RowId);
grdCategories.DataSource = ds.Tables[0].DefaultView;
grdCategories.DataBind();
}
Items Gridview Bind
protected void grdCategories_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridView chkTopings = e.Row.FindControl("grdItems") as GridView;
Label lblCategory = e.Row.FindControl("lblCategory") as Label;
FillItemsGrid(chkTopings, WebHelper.Cast(lblCategory.Text, 0));
}
}
protected void FillItemsGrid(GridView grdItems, int Category)
{
try
{
//int cleanOrder = CargoBag.GetValue("CleanOrder", 0);
DataSet aDataSet = new DataSet();
ItemBL bl = new ItemBL(SessionContext.SystemUser);
bl.FetchForCategory(aDataSet, Category, RowId);
grdItems.DataSource = aDataSet.Tables[0];
grdItems.DataBind();
}
catch (Exception ex) { }
}
Sub Items Gridview Bind
protected void grdItems_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridView grdSubItems = e.Row.FindControl("grdSubItems") as GridView;
Label lblItem = e.Row.FindControl("lblItem") as Label;
FillSubItemsGrid(grdSubItems, WebHelper.Cast(lblItem.Text, 0));
}
}
protected void FillSubItemsGrid(GridView grdSubItems, int Item)
{
try
{
//int cleanOrder = CargoBag.GetValue("CleanOrder", 0);
DataSet aDataSet = new DataSet();
SubItemBL bl = new SubItemBL(SessionContext.SystemUser);
bl.FetchForItem(aDataSet, Item);
grdSubItems.DataSource = aDataSet.Tables[0];
grdSubItems.DataBind();
}
catch (Exception ex) { }
}
You need to provide all of your code before we can provide an accurate answer.
For example:
Where SubItemBL is defined?
Also try to see what line is the exact bottleneck.
Is it
bl.FetchForCategory(aDataSet, Category, RowId);
or
grdSubItems.DataBind();
If above line is the bottleneck, note that Gridview binding to a datasource with large number of data is indeedslow. how large is your data?

Gridview on Content page RowCommand does not fire - ViewState?

The problem I'm having is the RowCommand of my GridView will not fire. I've read through millions of posts, and as a result I think I'm even more confused. So, if you can see what specifically it is I've done wrong here, please point it out.
I did ask a similar question a couple of weeks ago, but I was using a gridview nested in a datalist and using 'Include' Siblings of the EntityDataSource to display the Siblings, which are the many side of the relationship to Referral, it's fine for display, but figuring out Edit Update and Delete was nightmareish. So I've tied to simplify it, but am now stopped in my tracks because I'm losing controls somewhere in the postbacks.
I have a master page with a ContentPlaceholder:
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="Site.Master.cs" Inherits="HomelessStudent.Web.SiteMasterPage" ViewStateMode="Inherit" EnableViewState="True" %>
<asp:ContentPlaceHolder ID="ContentPlaceHolderAgent" runat="server">
</asp:ContentPlaceHolder>
On the Agent page-
<asp:Content ID="Content" ContentPlaceHolderID="ContentPlaceHolderAgent" runat="server">
<asp:Panel ID="SiblingPanel" runat="server" ViewStateMode="Enabled" Visible="True">
<asp:GridView ID="SiblingGridView" runat="server" CssClass="grid"
AutoGenerateColumns="false"
DataKeyNames="Id"
ShowFooter="true"
OnDataBound="SiblingGridView_DataBound"
OnRowEditing="SiblingGridView_RowEditing"
OnRowUpdating="SiblingGridView_RowUpdating"
OnRowCommand="SiblingGridView_RowCommand"
OnRowDeleting="SiblingGridView_RowDeleting" ViewStateMode="Enabled" ClientIDMode="Static">
<Columns>
<asp:TemplateField HeaderText="Name" SortExpression="SiblingName">
<EditItemTemplate>
<asp:TextBox runat="server" Text='<%# Bind("SiblingName") %>' ID="TextBox1"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label runat="server" Text='<%# Bind("SiblingName") %>' ID="Label1"></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox runat="server" ID="NewSiblingName" ></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit" ShowHeader="false">
<EditItemTemplate>
<asp:LinkButton runat="server" Text="Update" CommandName="Update" ID="UpdateLinkButton" ></asp:LinkButton> <asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" CausesValidation="False" ID="LinkButton2"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton runat="server" Text="Edit" CommandName="Edit" ID="EditLinkButton" ClientIDMode="Static"></asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton runat="server" CommandName="AddNew" Text="Add" ID="AddNewLinkButton"></asp:LinkButton> </FooterTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" ShowHeader="True" HeaderText="Delete"></asp:CommandField>
</Columns>
</asp:GridView>
</asp:Panel>
Code behind (binding data here because show only those siblings that belong to a specific record, ID (Guid) for that record is in the queryString, maybe...
if (IsPostBack == false)
{
if (Request.QueryString["id"] == null)
{
if (Session["studentid"] == null)
{
Response.Redirect("StudentPage.aspx");
}
else
{
referral = GetMostRecentReferral((String)Session["studentid"]);
PopulateUI(referral);
}
}
else
{
referral = GetThisReferral(Request.QueryString["id"]);
PopulateUI(referral);
}
}
Then, in PopulateUI(referral)
some stuff...
FillSiblingGrid();
String studentId = ((referral.StudentID).ToString()).Trim();
getSelectedStudentDeatails(studentId);
Session["referralid"] = (Guid)referral.Id;
And fill siblings grid-
private void FillSiblingGrid()
{
if (referral != null)
{
List<Sibling> siblings = new List<Sibling>();
using (HomelessStudentDataEntities db = new HomelessStudentDataEntities())
{
siblings = (from s in db.Siblings
where s.ReferralID == referral.Id
select s).ToList();
}
if (siblings.Count > 0)
{
SiblingGridView.DataSource = siblings;
SiblingGridView.DataBind();
}
else
{
int TotalColumns = SiblingGridView.Rows[0].Cells.Count;
SiblingGridView.Rows[0].Cells.Clear();
SiblingGridView.Rows[0].Cells.Add(new TableCell());
SiblingGridView.Rows[0].Cells[0].ColumnSpan = TotalColumns;
SiblingGridView.Rows[0].Cells[0].Text = "No siblings found";
}
}
}
I faced the similar problem. Enabling the grid view state resolved the problem

Categories

Resources