|
hi guys i just want to perform custom paging in which at the footer of the grid view ,there must be a pager 'pervious/next with numeric'
this is what i did
[SIZE="4"][B]in aspx page[/B] [/SIZE]
<asp:GridView ID="TableGridView"
OnPageIndexChanging="TableGridView_PageIndexChanging"
runat="server" AutoGenerateColumns="False"
AllowPaging="True" AllowSorting="True" >
</asp:GridView>
<asp:Button ID="btnConnect" runat="server" Style="z-index: 113;
left: 260px; position: absolute; top: 143px" Text="Connect & Populate" OnClick="btnConnect_Click" />
[B][SIZE="4"]in code behind page [/SIZE][/B]
public partial class _Default : System.Web.UI.Page
{
public static DataTable Table = new DataTable();
ArrayList ParameterArray = new ArrayList();
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack && (bool)Session["IsConnectionInfoSet"]==true)
CreateTemplatedGridView();
}
protected void TableGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
//CreateTemplatedGridView();
TableGridView.PageIndex = e.NewPageIndex;
TableGridView.DataBind();
}
protected void btnConnect_Click(object sender, EventArgs e)
{
Session["IsConnectionInfoSet"] = true;
CreateTemplatedGridView();
}
void PopulateDataTable()
{
Table = new DataTable();
TableGridView.Columns.Clear();
SqlDataAdapter adapter = new SqlDataAdapter("select * from customer", "Data Source=OPWFMS-7KYGZ7SB;Initial Catalog=Mayank;User ID=sa;Password=sa");
adapter.Fill(Table);
}
void CreateTemplatedGridView()
{
// fill the table which is to bound to the GridView
PopulateDataTable();
// add templated fields to the GridView
TemplateField BtnTmpField = new TemplateField();
BtnTmpField.ItemTemplate =
new DynamicallyTemplatedGridViewHandler(ListItemType.Item, "...", "Command");
BtnTmpField.HeaderTemplate =
new DynamicallyTemplatedGridViewHandler(ListItemType.EditItem, "...", "Command");
TableGridView.Columns.Add(BtnTmpField);
for (int i = 0; i < Table.Columns.Count; i++)
{
TemplateField ItemTmpField = new TemplateField();
// create HeaderTemplate
ItemTmpField.HeaderTemplate = new DynamicallyTemplatedGridViewHandler(ListItemType.Header,
Table.Columns[i].ColumnName,
Table.Columns[i].DataType.Name);
// create ItemTemplate
ItemTmpField.ItemTemplate = new DynamicallyTemplatedGridViewHandler(ListItemType.Item,
Table.Columns[i].ColumnName,
Table.Columns[i].DataType.Name);
//create EditItemTemplate
// then add to the GridView
TableGridView.Columns.Add(ItemTmpField);
}
// bind and display the data
TableGridView.DataSource = Table;
TableGridView.DataBind();
}
}
[SIZE="4"][B]and in the class file[/B][/SIZE]
public class DynamicallyTemplatedGridViewHandler : ITemplate
{
ListItemType ItemType;
string FieldName;
string InfoType;
public DynamicallyTemplatedGridViewHandler(ListItemType item_type, string field_name, string info_type)
{
ItemType = item_type;
FieldName = field_name;
InfoType = info_type;
}
public void InstantiateIn(System.Web.UI.Control Container)
{
switch (ItemType)
{
case ListItemType.Header:
Literal header_ltrl = new Literal();
header_ltrl.Text = "<b>" + FieldName + "</b>";
Container.Controls.Add(header_ltrl);
break;
case ListItemType.Item:
switch (InfoType)
{
case "Command":
break;
default:
Label field_lbl = new Label();
field_lbl.ID = FieldName;
field_lbl.Text = String.Empty; //we will bind it later through 'OnDataBinding' event
field_lbl.DataBinding += new EventHandler(OnDataBinding);
Container.Controls.Add(field_lbl);
break;
}
break;
}
}
private void OnDataBinding(object sender, EventArgs e)
{
object bound_value_obj = null;
Control ctrl = (Control)sender;
IDataItemContainer data_item_container = (IDataItemContainer)ctrl.NamingContainer;
bound_value_obj = DataBinder.Eval(data_item_container.DataItem, FieldName);
switch (ItemType)
{
case ListItemType.Item:
Label field_ltrl = (Label)sender;
field_ltrl.Text = bound_value_obj.ToString();
break;
}
}
}
[SIZE="4"][B]but for my requirements I want to use that code [/B][/SIZE]
class NumericWithNext : ITemplate
{
GridView localGrid;
int intSlotNo = 0;
#region CONTRUCTOR
public NumericWithNext(GridView gv)
{
localGrid = gv;
//intSlotNo = slotNo;
intSlotNo = localGrid.PageIndex / 10;
//constructor
}
public void InstantiateIn(Control container)
{
LinkButton prevTenRecords = new LinkButton();
prevTenRecords.Text = "Previous 10 Pages";
prevTenRecords.CssClass = "PagingLnks";
prevTenRecords.CommandArgument = ((intSlotNo - 1) * 10 + 1).ToString(); ;
prevTenRecords.CommandName = "Page";
//prevTenRecords.Click += new EventHandler(prevTenRecords_Click);
prevTenRecords.Width = Unit.Pixel(125);
if (intSlotNo > 0)
{
container.Controls.Add(prevTenRecords);
}
LinkButton nextTenRecords = new LinkButton();
nextTenRecords.Text = "Next 10 Pages";
nextTenRecords.CommandName = "Page";
nextTenRecords.CommandArgument = ((intSlotNo + 1) * 10 + 1).ToString();
// nextTenRecords.Click += new EventHandler(nextTenRecords_Click);
nextTenRecords.CssClass = "PagingLnks";
nextTenRecords.Width = Unit.Pixel(118);
// nextTenRecords.Visible = false;
LinkButton prev = new LinkButton();
prev.Text = "Previous Page";
prev.CssClass = "PagingLnks";
prev.CommandArgument = "Prev";
prev.CommandName = "Page";
prev.Width = Unit.Pixel(90);
if (localGrid.PageIndex > 0)
{
container.Controls.Add(prev);
}
//for (int pagenum = 1; pagenum <= localGrid.PageCount; pagenum++)
for (int pagenum = (intSlotNo*10)+1; pagenum <= (intSlotNo+1)*10; pagenum++)
{
if (pagenum > localGrid.PageCount)
{
nextTenRecords.Visible = false;
break;
}
LinkButton pageInd = new LinkButton();
if (pagenum == localGrid.PageIndex + 1)
{
//pageInd.ForeColor = System.Drawing.Color.Green;PagingSelected
pageInd.CssClass = "PagingSelected";
}
else
{
pageInd.CssClass = "PagingLnks";
}
pageInd.ID = "PageInd_" + pagenum;
pageInd.Text = pagenum.ToString();
pageInd.CommandName = "Page";
pageInd.CommandArgument = pagenum.ToString();
container.Controls.Add(pageInd);
pageInd.Width = Unit.Pixel(10);
}
LinkButton next = new LinkButton();
next.Text = " Next Page";
next.CommandName="Page";
next.CommandArgument = "Next";
next.CssClass = "PagingLnks";
next.Width = Unit.Pixel(80);
if (localGrid.PageIndex < localGrid.PageCount - 1)
{
container.Controls.Add(next);
}
container.Controls.Add(nextTenRecords);
}
void nextTenRecords_Click(object sender, EventArgs e)
{
//throw new Exception("The method or operation is not implemented.");
intSlotNo++;
}
void prevTenRecords_Click(object sender, EventArgs e)
{
//throw new Exception("The method or operation is not implemented.");
intSlotNo--;
}
plz let me know how can i do that
|
|
|
|
|
did u got the solution ? if not reply me i will giv eu
sabarimd
|
|
|
|
|
no,i did not get the solution
|
|
|
|
|
hi sir
please help me
i have a gridview and one column of gridview contain linkbutton another column has visibility false and named as locked.
locked column contain value y and n.
now suppose i click on link button then i want to change the value of locked column for that particular row.
how it will possible.
|
|
|
|
|
Hi All,
can any one please say any method is available for finding out number of hits by a user on a single page? (not site visit)
Regards
Lijo
|
|
|
|
|
Hit Counter for Particular Page.
1. Use database table to increment the Hit Counter
2. Call the update function(to increment the hit counter) in page_load event.
Regards,
Karthik K...
|
|
|
|
|
Create your own method which will load hitcounter value and increase it by 1.This method call in Page_Load event.
For more check this.[^]
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
Hello every one,
I am new comer in software field.I am developing a website,
I don't have an idea about creating role and all these things.
Then tell me about
1.how to create a role.
2.How to asign them access right.
3.Should i manage them in database or any other place.
Fianlly give basic idea about Admin module.
|
|
|
|
|
|
Hi all,
I am trying to bind a datatable to a Gridview,
In each row i add a usercontrol, The table has 8 rows,
The problem is when i call the GridView.Databind() method,
and extra row is added to the gridview i.e. the gridview displays 9 rows on the page.
What could be the cause of this?
Thanks & Regards,
Pramod
"Everyone is a genius at least once a year"
|
|
|
|
|
AB7771 wrote: In each row i add a usercontrol,
To where you are adding this? To a new column?
Hard to give suggestions without seeing the code.
|
|
|
|
|
I am binding a dataset to a Gridview.
Gridview1.DataSource = dtTable;
GridView1.DataBind();
And in the GridView1_RowCreated() method
I add the usercontrol for each row.
TableCell cell = new TableCell();
e.row.cells[0].Add(LoadControl("~/Usercontrol1.ascx"));
Hope that clears it.
Thanks & Regards,
Pramod
"Everyone is a genius at least once a year"
|
|
|
|
|
I have a checkbox in my form. When the checkbox is checked , i want to fire a javascript which makes some controls as visible or not visible. I have writtent the code,but the javascript is not firing. Can anybody please help me on that? Am I doing something wrong here?
Following is my code:
<script type="text/javascript">
function SetCopyPermissionsControlState(panelControlId, checkBox) {
alert("hai");
var enabled = checkBox.checked;
var panelControl = document.getElementById(panelControl);
if (panelControl)
{
if (enabled)
{
panelControl.style.display = 'block';
}
else
{
panelControl.style.display = 'none';
}
}
<tr><td class="labeltext"><asp:CheckBox ID="chkCopyPermissions" runat="server" Text = "CopyPermissions;"
OnClick="SetCopyPermissionsControlState(CopyPermissionsPanel,this)" /></td>
<td><asp:Label ID="lblCopyPermissionMessage" runat="server" ></asp:Label></td>
</tr>
<tr>
<asp:Panel ID = "CopyPermissionsPanel" runat = "server" Visible="false">
<td class="labeltext"><asp:Label ID = "lblCopyPermissions" runat = "server" Text = "Existing UserName" ></asp:Label></td>
<td><asp:TextBox id = "ExistingLoginTextBox" runat="server" TextMode="SingleLine" MaxLength="50"></asp:TextBox>
<asp:Button ID = "CopyPermissionsButton" runat="server" Text="Copy" OnClick="CopyPermissionsButton_Click" />
</td>
</asp:Panel>
</tr>
Please help.
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
|
|
|
|
|
var panelControl = document.getElementById(panelControl);
Please pass the actual proper id to the method. I guess it should be panelControlId
Thanks & Regards,
Pramod
"Everyone is a genius at least once a year"
|
|
|
|
|
meeram395 wrote: var panelControl = document.getElementById(panelControl);
Shouldn't this be var panelControl = document.getElementById(panelControlId); ?
meeram395 wrote: OnClick="SetCopyPermissionsControlState(CopyPermissionsPanel,this)"
Don't you need a single quote (')? OnClick="SetCopyPermissionsControlState('CopyPermissionsPanel',this)
When you are using server control id in JS, best practice is to use ClientId . Your code will break if you plan to make the panel as a child of some other container control because ASP.NET will change the name when it render the control.
|
|
|
|
|
ok. thanks. now the javascript is firing. but the panelcontrolid is firing. I opened View-->Source, but couldn't find the control asp panel. what could be the issue? Any guess?
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
|
|
|
|
|
meeram395 wrote: but the panelcontrolid is firing.
What do you mean?
meeram395 wrote: I opened View-->Source, but couldn't find the control asp panel. what could be the issue?
Browsers only understand HTML. ASP.NET will convert ASP:Panel to HTML DIV (not sure) when it is rendering the page. So you don't see ASP:Panel in the view source.
|
|
|
|
|
I have removed the panel control and I put an id to row.Now it is working fine. Following is the codew:
<tr><td class="labeltext"><asp:CheckBox ID="chkCopyPermissions" runat="server" Text = "CopyPermissions"
OnClick="SetCopyPermissionsControlState('CopyPermissionsRow',this)" /></td>
<td><asp:Label ID="lblCopyPermissionMessage" runat="server" ></asp:Label></td>
</tr>
<tr id="CopyPermissionsRow" visible="false">
<td class="labeltext">
<asp:Label ID = "lblCopyPermissions" runat = "server" Text = "Existing UserName" ></asp:Label>
</td>
<td>
<asp:TextBox id = "ExistingLoginTextBox" runat="server" TextMode="SingleLine" MaxLength="50"></asp:TextBox>
<asp:Button ID = "CopyPermissionsButton" runat="server" Text="Copy" OnClick="CopyPermissionsButton_Click" />
</td>
</tr>
Because of the above change, the javascript function , SetCopyPermissionsControlState, is firing now. But the issue is, I made it visible=false when the page loads which is not happening. The page loads by displaying the controls. However, when I check the checkboxes, it is changing accordingly. Any idea why it is not happening for the first time?
I don't want postback, because there is a password textbox in the form which erases the value on postback.
Following is my javascript function:
function SetCopyPermissionsControlState(rowControlId, checkBox) {
var enabled = checkBox.checked;
alert("enabled" + enabled);
var rowControl = document.getElementById(rowControlId);
alert("panelControl" + rowControl);
if (rowControl)
{
if (enabled)
{
rowControl.style.display = '';
}
else
{
rowControl.style.display = 'none';
}
}
}
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
|
|
|
|
|
try to make auto post back property = true;
|
|
|
|
|
I don't want autopostback property to true, since there is a password textbox in the page which is losing value on postback. so everytime there is a postback, the user has to retype which is quite cumbersome.
Is there any other way?
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
|
|
|
|
|
In the HTML I have -
<%#ShowProjectUrl(Eval("website_url").ToString())%>
In the code behind I have -
protected string ShowProjectUrl(string projectUrl)
{
if (projectUrl != String.Empty)
return "<br />Project URL - <a href='" + projectUrl + "' target='_blank'>" + projectUrl + "</a><br /><br />";
else
return String.Empty;
}
The website is stored in the DB as www.XXX.com and passes to the function OK.
But when I click on the hyperlink at run time it navigates to -
http://localhost/www.XXX.com
If anyone know hoe to get rid of the localhost, it would be most appreciated.
Thanks.
|
|
|
|
|
u should plus http://www.xxx.com
going like dis
return "<br />Project URL - <a href='http://" + projectUrl + "' target='_blank'>" + projectUrl + "</a><br /><br />";
|
|
|
|
|
Thank you very much, that has worked!
|
|
|
|
|
hihi welcome.. n gud luck =D
|
|
|
|
|
hi all
Im using Ajax timer for web site asynchronously loads some details, so when i click one of that item sometimes it display this error,im not using any Resonse.Write().
Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near '
<!DOCTYPE html PUB'.
Pls help me solve this , this is bit urgent
Thanks
|
|
|
|