How to control page numbers in pagination? - c#

I have written below lines of code
public void UpdatePageLables(int aPageCount)
{
PageCount = (int)Math.Ceiling((decimal)aPageCount / PageSize);
int recordCount = PageCount;
if (PageSizeChanged != null)
{
HiddenField hd = new HiddenField();
int current;
current = PageIndex;
int pre;
int Next;
double dblPageCount = (double)((decimal)recordCount / decimal.Parse(lstPageSize.SelectedValue));
int pageCount = PageCount;
List<ListItem> pages = new List<ListItem>();
if (pageCount > 0)
{
// pages.Add(new ListItem("First", "1", PageIndex > 1));
current = PageIndex;
pre = --PageIndex;
PageIndex = current;
// pages.Add(new ListItem("Previous", pre.ToString(), PageIndex > 1));
for (int i = 1; i <= aPageCount; i++)
{
pages.Add(new ListItem(i.ToString(), i.ToString(), i != PageIndex));
}
int currentPage = PageIndex;
Next = ++PageIndex;
PageIndex = currentPage;
//pages.Add(new ListItem("Next", Next.ToString(), PageIndex < pageCount));
// pages.Add(new ListItem("Last", pageCount.ToString(), PageIndex < pageCount));
hd.Value = (pre.ToString());
}
rptPager.DataSource = pages;
rptPager.DataBind();
}
}
And in ascx file
<div class="pagination">
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false" OnClick="imgPre_Click"
data-rel="tooltip" data-original-title="previous page.">«</asp:LinkButton>
<asp:Repeater ID="rptPager" OnItemDataBound="rptPager_ItemDataBound" runat="server">
<ItemTemplate>
<asp:LinkButton ID="lnkPage" runat="server" Text = '<%#Eval("Text") %>' CommandArgument = '<%# Eval("Value") %>' Enabled = '<%# Eval("Enabled") %>' OnClick = "Page_Changed"></asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="false" OnClick="imgnext_Click"
data-rel="tooltip" data-original-title="next page."> »
</asp:LinkButton>
<div class="page-size"><span>Page Size: </span>
<asp:DropDownList runat="server" ID="lstPageSize" AutoPostBack="true" style="float:right"
OnSelectedIndexChanged="lstPageSize_SelectedIndexChanged">
<asp:ListItem Text="5" Value="5"></asp:ListItem>
<asp:ListItem Text="10" Value="10"></asp:ListItem>
<asp:ListItem Text="15" Value="15" Selected="True"></asp:ListItem>
<asp:ListItem Text="25" Value="25" ></asp:ListItem>
<asp:ListItem Text="50" Value="50"></asp:ListItem>
<asp:ListItem Text="75" Value="75"></asp:ListItem>
<asp:ListItem Text="100" Value="100"></asp:ListItem>
<asp:ListItem Text="150" Value="150"></asp:ListItem>
</asp:DropDownList>
</div>
</div>
Now I want to display only first seven page number links when there will be hundred page number links and rest of page number links should not be displayed.
When user will click on ... button then page numbers from 8 to 14 should get displayed and 1 to 7 should be hidden and so on.
Please help me !!!

You should only fill your list of pages with the pages you want. So if you want 7 pages (3 left to selected index and 3 right to selected index) you can do:
for (int i = PageIndex - 3; i <= PageIndex + 3; i++)
{
if (i > 0 && i <= aPageCount) {
{
//i is still inside total range of pages, so page can be added
pages.Add(new ListItem(i.ToString(), i.ToString(), i != PageIndex));
}
}
If you want other list of pages (like 7 next after PageIndex) you need to change the for loop.

Related

how to manipulate list of selected values in checkbox - C#

I have set up the following method for multiple selection from user and store it in CSV format in Database.
<div class="col-md-10" style="padding-top: 7px;">
<asp:CheckBoxList ID="CheckBoxList1" runat="server" DataTextField="language" DataValueField="language" AutoPostBack="True" RepeatLayout="OrderedList" Width="432px">
<asp:ListItem Value="Saturday">Saturday</asp:ListItem>
<asp:ListItem Value="Sunday">Sunday</asp:ListItem>
<asp:ListItem Value="Monday">Monday</asp:ListItem>
<asp:ListItem Value="Tuesday">Tuesday</asp:ListItem>
<asp:ListItem Value="Wednesday">Wednesday</asp:ListItem>
<asp:ListItem Value="Thursday">Thursday</asp:ListItem>
</asp:CheckBoxList>
</div>
private string CheckBoxListDataToCSV()
{
string selectedItems = String.Join(",",
CheckBoxList1.Items.OfType<ListItem>().Where(r => r.Selected)
Select(r => r.Text));
return selectedItems;
}
string str = CheckBoxListDataToCSV(); //This method to Add in datarow
My question is that how to populate back the values in their check boxes when Add/Edit activity perform.
Thanking in Advance
return dataset containing csv then
DataTable dt = dsPage.Tables[0];
string strArr = dt.Rows[0]["Training_Days"].ToString();
string[] Arr = strArr.Split(',');
for (int j = 0; j < Arr.Length; j++)
{
for (int i = 0; i < Arr.Length; i++)
{
if (CheckBoxList1.Items.FindByText(Arr[i]) != null)
{
CheckBoxList1.Items.FindByText(Arr[i]).Selected = true;
continue;
}
}
}

How to merge rows in gridview

I have some data in gridview as below.
I want to merge the rows in gridview as below.
I already tried with below code in RowDataBound() and PreRender(), the result is not the same as I want.
for (int rowIndex = GridView1.Rows.Count - 2; rowIndex >= 0; rowIndex--)
{
GridViewRow gvRow = GridView1.Rows[rowIndex];
GridViewRow gvPreviousRow = GridView1.Rows[rowIndex + 1];
for (int cellCount = 0; cellCount < gvRow.Cells.Count; cellCount++)
{
if (gvRow.Cells[cellCount].Text ==
gvPreviousRow.Cells[cellCount].Text)
{
if (gvPreviousRow.Cells[cellCount].RowSpan < 2)
{
gvRow.Cells[cellCount].RowSpan = 2;
}
else
{
gvRow.Cells[cellCount].RowSpan =
gvPreviousRow.Cells[cellCount].RowSpan + 1;
}
gvPreviousRow.Cells[cellCount].Visible = false;
}
}
}
In aspx,
<asp:GridView ID="GridView1" runat="server" Width="100%"
AutoGenerateColumns = "false" AlternatingRowStyle-BackColor = "#fffccc" HeaderStyle-ForeColor ="#ffffff"
HeaderStyle-BackColor = "#333" AllowPaging ="true" OnRowDataBound="GridView1_RowDataBound" PageSize = "20"
OnPageIndexChanging="GridView1_PageIndexChanging" OnPreRender="GridView1_PreRender">
<HeaderStyle Height="30px" />
<Columns>
<asp:TemplateField HeaderText="Client Company">
<ItemTemplate>
<asp:Label ID="lblClientCompany" runat="server" Text='<%# Eval("ClientCompany")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Position">
<ItemTemplate>
<asp:Label ID="lblPosition" runat="server" Text='<%# Eval("Position")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Candidate">
<ItemTemplate>
<asp:Label ID="lblCandidate" runat="server" Text='<%# Eval("Candidate")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
asp:Label ID="lblStatus" runat="server" Text='<%# Eval("Status")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<AlternatingRowStyle BackColor="#fffccc" />
</asp:GridView>
Please help me becasue I have no idea. Thanks.
You need to try the method in DataBound not RowDataBound
DataBound fires after the GridView control binds to a data source(after all rows bound).
RowDataBound fires for each row, when a data row is bound to data in a GridView control.
ASPX
<asp:GridView ID="GridView1" runat="server" Width="100%"
AutoGenerateColumns = "false" AlternatingRowStyle-BackColor = "#fffccc" HeaderStyle-ForeColor ="#ffffff"
HeaderStyle-BackColor = "#333" AllowPaging ="true" OnDataBound="GridView1_DataBound1" PageSize = "20"
OnPageIndexChanging="GridView1_PageIndexChanging">
<HeaderStyle Height="30px" />
<Columns>
<asp:TemplateField HeaderText="Client Company">
<ItemTemplate>
<asp:Label ID="lblClientCompany" runat="server" Text='<%# Eval("ClientCompany")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Position">
<ItemTemplate>
<asp:Label ID="lblPosition" runat="server" Text='<%# Eval("Position")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Candidate">
<ItemTemplate>
<asp:Label ID="lblCandidate" runat="server" Text='<%# Eval("Candidate")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
asp:Label ID="lblStatus" runat="server" Text='<%# Eval("Status")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<AlternatingRowStyle BackColor="#fffccc" />
</asp:GridView>
Code Behind
protected void GridView1_DataBound1(object sender, System.EventArgs e)
{
for (int rowIndex = GridView1.Rows.Count - 2; rowIndex >= 0; rowIndex--)
{
GridViewRow gvRow = GridView1.Rows[rowIndex];
GridViewRow gvPreviousRow = GridView1.Rows[rowIndex + 1];
for (int cellCount = 0; cellCount < gvRow.Cells.Count; cellCount++)
{
if (gvRow.Cells[cellCount].Text ==
gvPreviousRow.Cells[cellCount].Text)
{
if (gvPreviousRow.Cells[cellCount].RowSpan < 2)
{
gvRow.Cells[cellCount].RowSpan = 2;
}
else
{
gvRow.Cells[cellCount].RowSpan =
gvPreviousRow.Cells[cellCount].RowSpan + 1;
}
gvPreviousRow.Cells[cellCount].Visible = false;
}
}
}
}
As suggested by Vignesh Kumar, the processing can be done in the DataBound event, after all the rows have been populated.
In order to retrieve the fields values, I suggest adding them to the DataKeyNames attribute of the GridView:
<asp:GridView ID="GridView1" runat="server" DataKeyNames="ClientCompany,Position" OnDataBound="GridView1_DataBound" ... />
Here is the code to combine the cells:
protected void GridView1_DataBound(object sender, EventArgs e)
{
for (int currentRowIndex = 0; currentRowIndex < GridView1.Rows.Count; currentRowIndex++)
{
GridViewRow currentRow = GridView1.Rows[currentRowIndex];
CombineColumnCells(currentRow, 0, "ClientCompany");
CombineColumnCells(currentRow, 1, "Position");
}
}
private void CombineColumnCells(GridViewRow currentRow, int colIndex, string fieldName)
{
TableCell currentCell = currentRow.Cells[colIndex];
if (currentCell.Visible)
{
Object currentValue = GridView1.DataKeys[currentRow.RowIndex].Values[fieldName];
for (int nextRowIndex = currentRow.RowIndex + 1; nextRowIndex < GridView1.Rows.Count; nextRowIndex++)
{
Object nextValue = GridView1.DataKeys[nextRowIndex].Values[fieldName];
if (nextValue.ToString() == currentValue.ToString())
{
GridViewRow nextRow = GridView1.Rows[nextRowIndex];
TableCell nextCell = nextRow.Cells[colIndex];
currentCell.RowSpan = Math.Max(1, currentCell.RowSpan) + 1;
nextCell.Visible = false;
}
else
{
break;
}
}
}
}
I have created for first column in vb.net code behind:
Note: Column should be BoundField.
<asp:BoundField DataField="ProductID" HeaderText="ProductID">
<ItemStyle Width="70px" HorizontalAlign="Center" />
</asp:BoundField>
VB.Net code behind:
Private Sub gvGridView_DataBound(sender As Object, e As EventArgs) Handles gvGridView.DataBound
Dim rowCount As Integer = gvTranscript1.Rows.Count
Dim RowIndex As Integer = 0
Dim gvRow As GridViewRow
Dim gvPrevRow As GridViewRow
Dim cellIndex As Integer = 0
For RowIndex = rowCount - 2 To 0 Step -1
gvRow = gvTranscript1.Rows(RowIndex) 'second last
gvPrevRow = gvTranscript1.Rows(RowIndex + 1) 'last
'lblmsg.Text += gvRow.Cells(0).Text & " - " & gvPrevRow.Cells(0).Text & "<br>"
If gvRow.Cells(0).Text = gvPrevRow.Cells(0).Text Then
If gvPrevRow.Cells(cellIndex).RowSpan < 2 Then
gvRow.Cells(cellIndex).RowSpan = 2
Else
gvRow.Cells(cellIndex).RowSpan = gvPrevRow.Cells(cellIndex).RowSpan + 1
End If
gvPrevRow.Cells(0).Visible = False
End If
Next
End Sub
Dim rows = GridView1.Rows.Cast(Of GridViewRow).Union(GridView2.Rows.Cast(Of GridViewRow)).ToArray().Select(Function(f) New With {.YourColumn1 = f.Cells(0).Text, .YourColumn2 = f.Cells(1).Text, .YourColumnN = f.Cells(n).Text})
GridView1.DataSource = rows
GridView1.DataBind()
Remove ItemTemplate and take boundField Columns

How to call ajax modalpop with dynamically created buttons?

I'm dynamically creating buttons with values from a database, and I have a modalpopup using ajax. I know that when using the popup I have to set a targetid, that's fine when its a predefined button. But how do you get the modalpopup to recognize a target when it dynamically created without having to use stringbuilder and rebuild a modalpopup on an eventhandler, and if I'm left to using stringbuilder then how do I call that when its created?
This is the code for the buttons
button.ID = Convert.ToString(myID);
button.Text = myStr;
button.PostBackUrl = "~/WebForm2.aspx?SubjectID=" + myID;
button.CssClass = "DynamicButtonOverlay";
This is the modalpopup
<asp:Panel ID="MyPanel" runat="server" CssClass="myModalPopup">
<table style="width:100%;">
<tr>
<td>Select News</td>
</tr>
<tr>
<td>
<asp:DropDownList ID="ddNewsToDelete" runat="server" CssClass="form-control"></asp:DropDownList>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>
<asp:Button ID="btnDeleteNews" runat="server" Text="Radera" CssClass="btn btn-danger pull-left" OnClick="btnDeleteNews_Click" CausesValidation="False" />
<asp:Button ID="btnClose" runat="server" Text="Close" class="btn btn-success pull-right" />
</td>
</tr>
</table>
</asp:Panel>
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" PopupControlID="MyPanel" BackgroundCssClass="myModalBackground" TargetControlID="Submit1" OkControlID="btnClose"></asp:ModalPopupExtender>
This is the code generating the buttons..
test.GetSubjects();
int subjectid = 0;
// Current row count.
int rowCtr;// = 0;
// Total number of cells per row (columns).
int cellCtr;
// Current cell counter.
int cellCnt;
//count number of rows in dataset
int rN = test.dsSubjects.Tables[0].Rows.Count;
cellCnt = 4;
for (rowCtr = 1; rowCtr <= rN; rowCtr++)
{
// Create a new row and add it to the table.
TableRow tRow = new TableRow();
Table1.Rows.Add(tRow);
for (cellCtr = 1; cellCtr <= 4; cellCtr++)
{
//
Button button = new Button();
//
HyperLink link = new HyperLink();
// Create a new cell and add it to the row.
TableCell tCell = new TableCell();
/* If the rowcounter is equal to the record numbers
* then it has to break because if not it will throw an error
* saying that there is no row at ending position */
if (rowCtr == rN)
break;
string myStr = test.dsSubjects.Tables[0].Rows[rowCtr - 1]["SubjectName"].ToString();
int myID = Convert.ToInt32(test.dsSubjects.Tables[0].Rows[rowCtr - 1]["SubjectID"].ToString());
button.ID = Convert.ToString(myID);
button.Text = myStr;
button.PostBackUrl = "~/WebForm2.aspx?SubjectID=" + myID;
button.CssClass = "DynamicButtonOverlay";
tCell.Controls.Add(button);
tCell.CssClass = "DynamicButtonOverlay";
tRow.Cells.Add(tCell);
rowCtr++;
/* If the cellcount is 3 then it needs to break, if not then
* you'll miss every 4rth record, don't know why. But this works */
if (cellCtr == 4)
{
rowCtr = rowCtr - 1;
break;
}
}
}

How do I dynamically add a user control based on user input?

I have a user control (.ascx) added to my application:
<uc1:pomedsrow runat="server" id="POMedsRow" />
And here is html and logic
<asp:Panel ID="Panel1" runat="server">
How many PO Meds do you wish to order?
<asp:TextBox ID="txtReqPONum" runat="server" />
<asp:LinkButton ID="lbnAddPOMeds" runat="server" Text="Go"
OnClick="lbnAddPOMeds_Click"/>
</asp:Panel>
<asp:Panel ID="pnlPOMeds" Visible="false" runat="server">
<table border="1">
<tr>
<td><p>PO Meds</p></td>
<td><p>Min/Max</p></td>
<td><p>Amount to Order</p></td>
</tr>
<uc1:pomedsrow runat="server" id="POMedsRow" />
</table>
<br />
</asp:Panel>
protected void lbnAddPOMeds_Click(object sender, EventArgs e)
{
int ReqPO = Convert.ToInt32(txtReqPONum.Text);
int n = ReqPO;
for (int i = 0; i < n; i++)
{
Control pomedsrow = new Control();
//Assigning the textbox ID name
pomedsrow.ID = "txtPOAmount" + "" + ViewState["num"] + i;
this.Form.Controls.Add(pomedsrow);
}
}
But when I click the link button nothing happens. Am I not calling the custom control correctly?
You are not adding your control properly. Try this:
protected void lbnAddPOMeds_Click(object sender, EventArgs e)
{
TextBox txtReqPONum = (TextBox) Panel1.FindControl("txtReqPONum");
int ReqPO = 0;
if (txtReqPONum != null && int.TryParse(txtReqPONum.Text, out ReqPO) )
{
int n = ReqPO;
for (int i = 0; i < n; i++)
{
UserControl myControl = (UserControl)Page.LoadControl("~/pomedsrow.ascx");//(UserControl)Page.LoadControl("Your control path/pomedsrow.ascx");
//Assigning the textbox ID name
myControl.ID = "txtPOAmount" + "" + ViewState["num"] + i;
Panel1.Controls.Add(myControl);
}
}
}

Telerik Radgrid : adding another footer row

I need to add multiple footer rows to my RadGrid instance ; for the moment, however, I just want to add second one. I have currently a single footer row and it's working and displaying perfectly, for the record.
I found the following relevant question on the Telerik forums and tried implemeting it but it's not working : the code gets executed, and the new FooterItem gets added to the Controls but that second row just doesn't appear. I need to find out why and I'd be grateful if anyone could help me fix that problem.
ASP grid code
<div id="OrderMainContent">
<telerik:RadAjaxManager runat="server" ID="RadAjaxManager1">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadGrid1" />
<telerik:AjaxSetting AjaxControlID="txtQuantity">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadInputManager ID="RadInputManager1" runat="server">
<telerik:NumericTextBoxSetting BehaviorID="NumericBehavior1" Type="Number" DecimalDigits="0">
<TargetControls>
<telerik:TargetInput ControlID="RadGrid1" />
</TargetControls>
</telerik:NumericTextBoxSetting>
</telerik:RadInputManager>
<telerik:RadGrid ID="RadGrid1" runat="server" Skin="Sunset" AllowSorting="True" AutoGenerateColumns="False"
GridLines="None" ShowFooter="True" OnItemDataBound="RadGrid1_ItemDataBound" OnPreRender="RadGrid1_PreRender">
<MasterTableView DataKeyNames="ProductID" TableLayout="Fixed">
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn UniqueName="colProduct" HeaderText="<%$ Resources: SiteLabels, ProductOrderForm.lblProduct %>"
HeaderStyle-HorizontalAlign="Center" DataField="ProdDesc">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn UniqueName="colQuantity" HeaderText="<%$ Resources: SiteLabels, ProductOrderForm.lblQuantity %>"
HeaderStyle-HorizontalAlign="Center" DataField="OrderQty" ColumnEditorID="txtQuantity">
<HeaderStyle Width="90" />
<ItemStyle Width="90px" />
<ItemTemplate>
<asp:TextBox ID="txtQuantity" runat="server" Width="50px" OnTextChanged="txtQuantity_TextChanged"
AutoPostBack="true">
</asp:TextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="colPrice" HeaderText="<%$ Resources: SiteLabels, ProductOrderForm.lblBasePrice %>"
HeaderStyle-HorizontalAlign="Center" DataField="ProdUnitPrice">
<HeaderStyle Width="80px" />
<ItemStyle Width="80px" />
<ItemTemplate>
<asp:Label ID="lblPrice" runat="server" Text='<%# Eval("ProdUnitPrice") %>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn UniqueName="colNotes" HeaderText="<%$ Resources: SiteLabels, ProductOrderForm.lblNotes %>"
HeaderStyle-HorizontalAlign="Center">
<HeaderStyle Width="200px" />
<ItemStyle Width="200px" />
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<ClientSettings>
<Scrolling AllowScroll="True" UseStaticHeaders="True" />
</ClientSettings>
</telerik:RadGrid>
</div>
Relevant code behind
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
AddFooterRow(sender as RadGrid);
}
private void AddFooterRow(RadGrid grid)
{
if (grid != null)
{
GridItem[] footerItems = grid.MasterTableView.GetItems(GridItemType.Footer);
if (footerItems.Count() == 1)
{
GridTFoot foot = footerItems[0].Parent.Controls[0].Parent as GridTFoot;
for (int i = 0; i < foot.Controls.Count; i++)
{
GridFooterItem item = foot.Controls[i] as GridFooterItem;
if(item != null)
{
lastFooterPos = i;
break;
}
}
GridFooterItem existingFooter = foot.Controls[lastFooterPos] as GridFooterItem;
GridFooterItem newFooterItem = new GridFooterItem(grid.MasterTableView, 0, 0);
foreach(TableCell fc in existingFooter.Cells)
{
TableCell newFooterCell = new TableCell();
newFooterCell.Text = "allo";
newFooterItem.Cells.Add(newFooterCell);
}
foot.Controls.AddAt(lastFooterPos + 1, newFooterItem);
}
}
}
Of course if you need more precisions, just ask. Thank you for your help.
After doing some searching on the Telerik docs, I'm fairly sure this is not just possible. In this question, for instance, a Telerik admin states clearly that "RadGrid is data-bound control and its items are created based on the records in its datasource and display the datasource data. Therefore in order to add new row in the grid, you need to add new record in its datasource and rebind the grid."
So, to work around my problem, I've decided to remove the footer on my grid and add a brand-new grid underneath, which I'll bind to a dummy DataTable I'll create by code in my Page_Load event handler. The values will be either determined client-side through Javascript or simply injected into the rows of that dummy table.
If anyone ever finds a more elegant solution, I'm still interested to know about it! Right now, though, work has to go forward.
int lastFooterPos;
protected void RadGrid1_PreRender(object sender, EventArgs e) {
AddFooterRow(sender as RadGrid);
}
private void AddFooterRow(RadGrid grid) {
if (grid != null) {
GridItem[] footerItems = grid.MasterTableView.GetItems(GridItemType.Footer);
if (footerItems.Length == 1) {
GridTFoot foot = footerItems[0].Parent.Controls[0].Parent as GridTFoot;
for (int i = 0; i < foot.Controls.Count; i++) {
GridFooterItem item = foot.Controls[i] as GridFooterItem;
if (item != null) {
lastFooterPos = i;
break;
}
}
GridFooterItem existingFooter = foot.Controls[lastFooterPos] as GridFooterItem;
GridFooterItem newFooterItem = new GridFooterItem(grid.MasterTableView, 0, 0);
int k = 0;
int l = 0;
int n = 0;
int p = 0;
int a = 0;
int b = 0;
int c = 0;
foreach (TableCell fc in existingFooter.Cells) {
//decimal cost = Convert.ToDecimal(existingFooter["Marks"].Text);
TableCell newFooterCell = new TableCell();
if (k == 0) {
newFooterCell.Text = "";
newFooterCell.Height = 12;
newFooterItem.Cells.Add(newFooterCell);
k = 1;
}
else {
if (l == 0) {
newFooterCell.Text = "";
newFooterCell.Height = 12;
newFooterItem.Cells.Add(newFooterCell);
l = 1;
}
else {
if (n == 0) {
newFooterCell.Text = "";
newFooterCell.Height = 12;
newFooterItem.Cells.Add(newFooterCell);
n = 1;
}
else {
if (p == 0) {
newFooterCell.Text = "Another Total Footer:";
newFooterCell.Height = 12;
newFooterItem.Cells.Add(newFooterCell);
p = 1;
}
else {
if (a == 0) {
newFooterCell.Text = Convert.ToString(existingFooter["Marks"].Text);
newFooterCell.Height = 12;
newFooterItem.Cells.Add(newFooterCell);
a = 1;
}
else {
if (b == 0) {
newFooterCell.Text = Convert.ToString(existingFooter["Fees"].Text);
newFooterCell.Height = 12;
newFooterItem.Cells.Add(newFooterCell);
b = 1;
}
else {
if (c == 0) {
newFooterCell.Text = Convert.ToString(existingFooter["Noofstudents"].Text);
newFooterCell.Height = 12;
newFooterItem.Cells.Add(newFooterCell);
c = 1;
}
else {
newFooterCell.Text = "";
newFooterCell.Height = 12;
newFooterItem.Cells.Add(newFooterCell);
}
}
}
}
}
}
}
foot.Controls.AddAt(lastFooterPos + 1, newFooterItem);
}
}
}
}

Categories

Resources