how to apply pagging to data list control - asp.net

i just want to make data list with pagging. here is my code :
public partial class Template_Management : System.Web.UI.Page
{
PagedDataSource adsource = null;
int pos;
protected void Page_Init(object sender, EventArgs e)
{
if (!IsPostBack)
{
adsource = new PagedDataSource();
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
.....
Session["StartAlpha"] = "All";
Session["GroupByCategory"] = -1;
Session["ColumnName"] = null;
Session["SearchText"] = null;
this.FillGrid((String)Session["StartAlpha"] ?? null, (int)Session["GroupByCategory"], (String)Session["ColumnName"] ?? null, (String)Session["SearchText"] ?? null);
this.ViewState["vs"] = 0;
}
pos = (int)this.ViewState["vs"];
}
}
public void FillGrid(string StartAlpha, int GroupByCategory, string ColumnName, string SearchText)
{
if (myDataSet.Tables[0].Rows.Count > 0)
{
adsource.DataSource = myDataSet.Tables[0].DefaultView;
adsource.AllowPaging = true;
adsource.PageSize = 20;
DL_ViewTemplate.DataSource = adsource;
}
if (DL_ViewTemplate.Items.Count != 0)
{
SetPageNumbers();
}
UpdatePanel8.Update();
DL_ViewTemplate.DataBind();
}
private void SetPageNumbers()
{
foreach (DataListItem item in DL_ViewTemplate.Items)
{
if (item.ItemType == ListItemType.Footer)
{
if (pos == 0)
{
ImageButton img = (ImageButton)item.FindControl("ImageButton1");
img.Enabled = false;
}
if (pos == adsource.PageCount - 1)
{
ImageButton img = (ImageButton)item.FindControl("ImageButton4");
img.Enabled = false;
}
}
}
}
protected void DL_ViewTemplate_ItemCommand(object source, DataListCommandEventArgs e)
{
int intCurIndex = adsource.CurrentPageIndex;
switch (e.CommandArgument.ToString())
{
case "first":
adsource.CurrentPageIndex = 0;
break;
case "prev":
CurrentPage -= 1;
break;
case "next":
CurrentPage += 1;
break;
case "last":
adsource.CurrentPageIndex = adsource.PageCount;
break;
}
this.FillGrid((String)Session["StartAlpha"] ?? null, (int)Session["GroupByCategory"], (String)Session["ColumnName"] ?? null, (String)Session["SearchText"] ?? null);
}
protected void DL_ViewTemplate_ItemDataBound(object sender, DataListItemEventArgs e)
{
foreach (DataListItem item in DL_ViewTemplate.Items)
{
if (item.ItemType == ListItemType.Footer && item.ItemType == ListItemType.Item)
{
// get your controls from the gridview
DropDownList ddlPages = (DropDownList)item.FindControl("ddlPages");
Label lblPageCount = (Label)item.FindControl("lblPageCount");
if (ddlPages != null)
{
// populate pager
for (int i = 0; i < adsource.PageCount; i++)
{
int intPageNumber = i + 1;
ListItem lstItem = new ListItem(intPageNumber.ToString());
if (i == adsource.CurrentPageIndex)
lstItem.Selected = true;
ddlPages.Items.Add(lstItem);
}
}
// populate page count
if (lblPageCount != null)
lblPageCount.Text = adsource.PageCount.ToString();
}
}
}
protected void ddlPages_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (DataListItem item in DL_ViewTemplate.Items)
{
if (item.ItemType == ListItemType.Footer)
{
DropDownList ddlPages = (DropDownList)item.FindControl("ddlPages");
adsource.CurrentPageIndex = ddlPages.SelectedIndex;
//a method to populate your grid
this.FillGrid((String)Session["StartAlpha"] ?? null, (int)Session["GroupByCategory"], (String)Session["ColumnName"] ?? null, (String)Session["SearchText"] ?? null);
}
}
}
}
how ever footer control with ddl doesn't filled.
for more info i place html markup :
<asp:DataList ID="DL_ViewTemplate" runat="server" RepeatColumns="6"
ShowFooter="True" HorizontalAlign="Left" RepeatDirection="Horizontal"
DataKeyField="Id" onitemcommand="DL_ViewTemplate_ItemCommand"
ShowHeader="False" onitemcreated="DL_ViewTemplate_ItemCreated"
onitemdatabound="DL_ViewTemplate_ItemDataBound" CellPadding="1"
CellSpacing="3">
<ItemStyle HorizontalAlign="Left" Wrap="True" Width="40%" />
<ItemTemplate>
<div class="thumb" align="center" style="height:150px;width:130px">
<table width="40%" align="center">
<tr>
<td>
<asp:Literal ID="Literal4" runat="server"></asp:Literal><!-- Text=<'#Eval("TemplateBody")%>'-->
<ajaxToolkit:HoverMenuExtender ID="hme1" runat="Server"
TargetControlID="Literal4"
PopupControlID="Panel2"
DynamicContextKey='<%# Eval("Id") %>'
DynamicControlID="Panel2"
DynamicServiceMethod="GetDynamicContent"
PopupPosition="Right"
OffsetX="-25"
OffsetY="15"/>
</td>
</tr>
</table>
</div>
<table width="145px" align="left" style="border-color:Black;border-style:solid;border-width:1px;height:50px">
<tr>
<td align="center">
<table>
<tr>
<td><asp:CheckBox ID="ChkSelect" runat="server" onclick = "Check_Click(this)"/></td>
<td> </td>
<td><asp:LinkButton ID="LinkButton2" runat="server" CssClass="quicklink"
Text='<%# Eval("TemplateName").ToString().Length > 12 ? Eval("TemplateName").ToString().Substring(0,12)+"..." :Eval("TemplateName") %>' CommandName="ViewTemplate"
ToolTip ='<%# Eval("TemplateName")%>' CommandArgument='<%# Eval("Id") %>'></asp:LinkButton>
<br/>
<asp:Label ID="Label2" runat="server" CssClass="normaltext"
Text='<%# DataBinder.Eval(Container.DataItem, "CreatedDate", "{0:dd/MM/yyyy}") %>'
ToolTip='<%# Bind("CreatedDate","{0:F}") %>'></asp:Label></td>
</tr>
</table>
</td>
</tr>
</table>
</ItemTemplate>
<SeparatorTemplate> </SeparatorTemplate>
<FooterTemplate>
<table>
<tr>
<td>
<asp:ImageButton ID="ImageButton1" runat="server"
AlternateText="Go to First Page" CommandArgument="First" CommandName="Page"
ImageUrl="images/1330128819_resultset_first.png" />
</td>
<td>
<asp:ImageButton ID="ImageButton2" runat="server" AlternateText="Previous Page"
CommandArgument="Prev" CommandName="Page"
ImageUrl="images/1330128981_resultset_previous.png" />
</td>
<td>
Page <asp:DropDownList ID="ddlPages" runat="server" AutoPostBack="True"
onselectedindexchanged="ddlPages_SelectedIndexChanged" Width="50px">
</asp:DropDownList>
of
<asp:Label ID="lblPageCount" runat="server"></asp:Label>
</td>
<td>
<asp:ImageButton ID="ImageButton3" runat="server" AlternateText="Next Page"
CommandArgument="Next" CommandName="Page"
ImageUrl="images/Farm-Fresh_resultset_next.png" />
</td>
<td>
<asp:ImageButton ID="ImageButton4" runat="server"
AlternateText="Go to Last Page" CommandArgument="Last" CommandName="Page"
ImageUrl="images/1330128876_resultset_last.png" />
</td>
</tr>
</table>
</FooterTemplate>
<FooterStyle CssClass="pager" VerticalAlign="Bottom"
HorizontalAlign="Center" />
</asp:DataList>
here i set adsource which was paged data source declared first and assigned in Page_Init() is it valid ?? because when ever other event want to access adsource then Object reference not found error thrown.
what am i going wrong please help me....

you can refer these links for more information on paging on datalist control in ASP.net
http://www.c-sharpcorner.com/UploadFile/718fc8/paging-in-datalist-control/
http://www.codeproject.com/Articles/14080/Implementing-Efficient-Data-Paging-with-the-Datali

Related

use one function for multple checboxlist ASP.NET

I have a function that prevents you from marking more than 5 options, which is executed "OnSelectedIndexChanged="chkMaterialCuarto_SelectedIndexChanged"".
int a = chkMaterialCuarto.Items.Count;
int contador = 0;
for (int i = 0; i < a; i++)
{
if (chkMaterialCuarto.Items[i].Selected == true)
contador++;
}
if (contador > 5)
{
for (int i = 0; i < a; i++)
{
if (chkMaterialCuarto.Items[i].Selected == true)
{
chkMaterialCuarto.Items[i].Selected = false;
break;
}
}
}
but now I want to use it for 3 other checkboxlists without having to do a function for each checkboxlist.
this are my other chekboxlist
<div class="inner1">
<span class="labelBoldForm fleft">material wall: </span></br>
<asp:CheckBoxList ID="chkMaterialwall" class="labelBoldForm fleft" AutoPostBack="true" runat="server" OnSelectedIndexChanged="chkMaterialCuarto_SelectedIndexChanged"></asp:CheckBoxList>
</div>
<div class="inner1">
<span class="labelBoldForm fleft">materials silly : </span></br>
<asp:CheckBoxList ID="chkMaterialsilly" class="labelBoldForm fleft" AutoPostBack="true" runat="server" OnSelectedIndexChanged="chkMaterialCuarto_SelectedIndexChanged"></asp:CheckBoxList>
</div>
<div class="inner1">
<span class="labelBoldForm fleft">materials floor: </span></br>
<asp:CheckBoxList ID="chkfloor" class="labelBoldForm fleft" AutoPostBack="true" runat="server" OnSelectedIndexChanged="chkMaterialCuarto_SelectedIndexChanged"></asp:CheckBoxList>
</div>
how can i do that ?
This should work:
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
Max5Check((CheckBoxList)sender);
}
void Max5Check(CheckBoxList ckList)
{
int SelectedCount = 0;
foreach (ListItem MyCheck in ckList.Items)
{
if (MyCheck.Selected)
SelectedCount++;
if (SelectedCount > 5)
{
MyCheck.Selected = false;
return;
}
}
}

how to get html chekbox at code behind with asp.net 4.0

here this is my html markup :
<asp:TemplateField>
<HeaderTemplate>
<div class="form-check">
<input type="checkbox" id="chkAll" runat="server" class="form-check-input checkAll" onclick="javascript: form1.submit();" onserverchange="Server_Changed" />
<label class="form-check-label">Roll No</label>
</div>
</HeaderTemplate>
<ItemTemplate>
<div class="form-check">
<input type="checkbox" id="chkSelect" runat="server" class="form-check-input" />
<label class="form-check-label">
<asp:LinkButton runat="server" CausesValidation="false" ID="lnkID" CommandName="detail"
CommandArgument='<%#Bind("ID") %>' ToolTip="View Detail"
Text='<%# string.Concat("#",Eval("RollNo"))%>'
Font-Underline="true">
</asp:LinkButton>
</label>
</ItemTemplate>
</asp:TemplateField>
and here is my code :
protected void Server_Changed(object sender, EventArgs e)
{
CheckBox chkAll = sender as CheckBox;
if (chkAll.Checked)
{
for (int i = 0; i <= egrd.Rows.Count - 1; i++)
{
GridViewRow row = egrd.Rows[i];
CheckBox Ckbox = (CheckBox)row.FindControl("chkSelect");
Ckbox.Checked = true;
}
}
else
{
for (int i = 0; i <= egrd.Rows.Count - 1; i++)
{
GridViewRow row = egrd.Rows[i];
CheckBox Ckbox = (CheckBox)row.FindControl("chkSelect");
Ckbox.Checked = false;
}
}
}
here i achieve get all checkbox selected from html checkbox checked changed event..
how i done this task ...please guys help me...
In your code behind you use CheckBox, but in the aspx you are not using the corresponding control (<asp:CheckBox) but a normal html checkbox with runat=server.
So you need to use HtmlInputCheckBox
using System.Web.UI.HtmlControls;
protected void Server_Changed(object sender, EventArgs e)
{
HtmlInputCheckBox chkAll = sender as HtmlInputCheckBox;
if (chkAll.Checked)
{
for (int i = 0; i <= egrd.Rows.Count - 1; i++)
{
GridViewRow row = egrd.Rows[i];
HtmlInputCheckBox Ckbox = (HtmlInputCheckBox)row.FindControl("chkSelect");
Ckbox.Checked = true;
}
}
else
{
for (int i = 0; i <= egrd.Rows.Count - 1; i++)
{
GridViewRow row = egrd.Rows[i];
HtmlInputCheckBox Ckbox = (HtmlInputCheckBox)row.FindControl("chkSelect");
Ckbox.Checked = false;
}
}
}

last image repeating in gridview

I want to display an image in grid view cell on specific condition andthe condition fails image not to be display.
<asp:GridView ID="gvWrkLogVW" runat="server" AutoGenerateColumns="False"
onrowdatabound="gvWrkLogVW_RowDataBound"
>
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Image ID="Image1" runat="server" Width="20px" Height="20px" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
On row data bound
if (e.Row.RowType == DataControlRowType.DataRow)
{
Image img = (Image)e.Row.FindControl("Image1");
for (int i = 0; i < dtWorkLogDeatils.Rows.Count; i++)
{
if (dtWorkLogDeatils.Rows[i]["email"].ToString() == "True")
{
img.ImageUrl = "/images/mail_send.png";
}
else
{
img.ImageUrl = "";
}
}
}
the last binding image is repeating all the columns.How to assign the image to particular cell

Asp.net Async page that call a Web Service Without use Visual Studio web reference

i need to call a web service without use webreference created with visual studio, i have to use
http web request i have the soap request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pos="http://posting.ws.rpg.snamretegas.it/">
<soapenv:Header/>
<soapenv:Body>
<pos:postAllReports>
<report_name>REPORT_SWITCH</report_name>
<report_date></report_date>
<i_ambiente>ITG1</i_ambiente>
<i_taxidOpco>TEST_YF1</i_taxidOpco>
</pos:postAllReports>
</soapenv:Body>
</soapenv:Envelope>
this is the code behind asp page:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.OracleClient;
public partial class PubreportControl : System.Web.UI.Page
{
private DB_Utility dbu;
protected double size = 1;
private string connectionString;
private OracleConnection connection;
private OracleCommand processNumQuery;
private int indexdropitem;
private int coloreriga = 1;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["CONNECTSTRING"] = Request["CONNECTSTRING"];
if (Session["CONNECTSTRING"] == null)
{
Response.Redirect("sessionup.asp?type=Pubreport");
}
connectionString = Session["CONNECTSTRING"].ToString();
if (connectionString.IndexOf("DSN=") >= 0)
{
Comuni.Utility util = new Utility();
connectionString = util.ConnStr(connectionString);
Session["CONNECTSTRING"] = connectionString;
}
connection = new OracleConnection(connectionString);
connection.Open();
dbu = new DB_Utility(Session["CONNECTSTRING"].ToString());
}
else
{
connectionString = Session["CONNECTSTRING"].ToString();
if (connectionString.IndexOf("DSN=") >= 0)
{
Comuni.Utility util = new Utility();
connectionString = util.ConnStr(connectionString);
Session["CONNECTSTRING"] = connectionString;
}
connection = new OracleConnection(connectionString);
connection.Open();
dbu = new DB_Utility(Session["CONNECTSTRING"].ToString());
}
if (!IsPostBack)
{
processNumQuery = new OracleCommand("select distinct nome_report from rpg_notification",connection);
OracleDataReader reader = processNumQuery.ExecuteReader();
while (reader.Read())
{
dropdownlist1.Items.Insert(0, new ListItem(reader.GetString(0), reader.GetString(0)));
}
reader.Close();
}
if(Request["txtSchedDate"] == null)
{
DateTime daDate = DateTime.Today;
txtSchedDate.Text = daDate.ToString("dd/MM/yyyy");
}
else
{
txtSchedDate.Text = Request["txtSchedDate"];
gwreportpub.DataSource = getDatiFromDb();
gwreportpub.DataBind();
DateTime schedDate = Convert.ToDateTime(Request["txtSchedDate"]);
string reportname = dropdownlist1.SelectedItem.Text;
object[] WSMethodArguments = new object[3];
WSMethodArguments[0] = reportname;
WSMethodArguments[1] = schedDate.ToUniversalTime().ToString("s");
WSMethodArguments[2] = "ITG1";
PageAsyncTask task = new PageAsyncTask(
new BeginEventHandler(BeginAsyncOperation),
new EndEventHandler(EndAsyncOperation),
new EndEventHandler(TimeoutAsyncOperation),
WSMethodArguments
);
RegisterAsyncTask(task);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
//Response.Write("ciao " + dropdownlist1.SelectedIndex + " - " + dropdownlist1.SelectedItem.Text + " - " + dropdownlist1.Items[dropdownlist1.SelectedIndex].Text + " - " + Request["txtSchedDate"] + " - ");
//ThreadPool.QueueUserWorkItem(new WaitCallback(callWebService),new object[] {"http://172.19.241.235:9001/snam-rpg-ws/ReportPosting","ReportPosting","postAllReports",WSMethodArguments});
gwreportpub.DataSource = getDatiFromDb();
gwreportpub.DataBind();
gwreportpub.Visible = true;
if (gwreportpub.Rows.Count == 0)
{
tbnotif.Text = "Non vi sono report pubblicati";
tbnotif.Visible = true;
}
else{
tbnotif.Visible = true;
tbnotif.Text = "Tabella dei Report Pubblicati: ";
}
return;
}
void TimeoutAsyncOperation(IAsyncResult ar)
{
Response.Write("Pubblicazione Timeout");
}
IAsyncResult BeginAsyncOperation (object sender, EventArgs e,
AsyncCallback cb, object state)
{
object[] array = state as object[];
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(#"http://172.19.241.235:9001/snam-rpg-ws/ReportPosting");
webRequest.Headers.Add(#"SOAP:Action");
webRequest.ContentType = "text/xml;charset=\"utf-8\"";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
HttpWebRequest request = webRequest;
XmlDocument soapEnvelopeXml = new XmlDocument();
soapEnvelopeXml.LoadXml("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:pos=\"http://posting.ws.rpg.snamretegas.it/\"><soapenv:Header/><soapenv:Body><pos:postAllReports><report_name> " + array[0] +" </report_name> <report_date> " + array[1] + "</report_date> <i_ambiente> " + array[2] + "</i_ambiente> <i_taxidOpco></i_taxidOpco></pos:postAllReports></soapenv:Body></soapenv:Envelope>");
using (Stream stream = request.GetRequestStream())
{
soapEnvelopeXml.Save(stream);
}
using (WebResponse response = request.GetResponse())
{
using (StreamReader rd = new StreamReader(response.GetResponseStream()))
{
string soapResult = rd.ReadToEnd();
}
}
SampleMethodCaller smd = new SampleMethodCaller(SampleClass.SampleMethod);
IAsyncResult result = smd.BeginInvoke(null, null);
return result;
//return callWebService(new object[] {"http://172.19.241.235:9001/snam-rpg-ws/ReportPosting","ReportPosting","postAllReports",state});
}
public delegate bool SampleMethodCaller();
void EndAsyncOperation(IAsyncResult ar)
{
Response.Write("Pubblicazione Terminata");
}
protected void Page_PreRenderComplete(object sender, EventArgs e)
{
}
public DataSet getDatiFromDb()
{
OracleDataAdapter adapter = new OracleDataAdapter();
OracleCommand orclc = new OracleCommand("select pubblicato, nome_report, data_report, md5 from rpg_notification where pubblicato = :flag and data_report <= TO_DATE(:repdate,'DD/MM/YYYY') and nome_report = :nome",this.connection);
orclc.Parameters.Add(new OracleParameter(":flag", OracleType.VarChar));
orclc.Parameters.Add(new OracleParameter(":nome", OracleType.VarChar));
orclc.Parameters.Add(new OracleParameter(":repdate", OracleType.VarChar));
orclc.Parameters[":flag"].Value = "Y";
orclc.Parameters[":nome"].Value = dropdownlist1.SelectedItem.Text;
orclc.Parameters[":repdate"].Value = Request["txtSchedDate"].ToString();
adapter.SelectCommand = orclc;
DataSet dt = new DataSet("rpg_notification");
adapter.Fill(dt,"rpg_notification");
return dt;
}
protected void GridView1_PageIndexChanging(object sender,
GridViewPageEventArgs e)
{
gwreportpub.PageIndex = e.NewPageIndex;
gwreportpub.DataBind();
}
protected void coloraRighe(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.Header)
{
e.Row.BackColor = Color.Ivory;
}
else if (coloreriga == 2)
{
e.Row.BackColor = Color.LightYellow;
coloreriga = 1;
}
else
{
e.Row.BackColor = Color.WhiteSmoke;
coloreriga = 2;
}
}
}
public class SampleClass
{
public static bool SampleMethod()
{
return true;
}
}
please can you tell me why it dose not call the Ws ???
and please how can i debug this ??? you see something wrong in the code ??
i m getting crazy about the async pattern too
in the end the asp page:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Pubreport.aspx.cs"
Inherits="PubreportControl" Title="Untitled Page" Async="true" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<script language="javascript" type="text/javascript">
var size = 0;
var id= 0;
function add_gif() {
document.getElementById("Label1").style.display = "none";
show_image("./wait.gif", 300,15, "Running");
}
function show_image(src, width, height, alt) {
var img = document.createElement("img");
img.src = src;
img.width = width;
img.height = height;
img.alt = alt;
document.getElementById("divUpload").style.display="inline";
var div = document.getElementById("divUpload");
div.appendChild(img);
}
function show_table() {
document.getElementById("tbnotification").style.display="block";
}
</script>
<head id="Head1" runat="server">
<title>Pubblicazione Report</title>
<link rel="stylesheet" type="text/css" href="../controls/SnapIn.css" />
<link rel="stylesheet" type="text/css" href="../controls/lsi18n.css" />
<script type="text/javascript" src="../cust_batchrequest/calendario/prototype.js"></script>
<script type="text/javascript" src="../cust_batchrequest/calendario/scriptaculous.js"> </script>
<script type="text/javascript" src="../cust_batchrequest/calendario/datepicker.js"></script>
<link rel="stylesheet" type="text/css" href="../cust_batchrequest/calendario/datepicker.css" />
<style type="text/css">
.errorMessage
{
color: #8B0000;
text-align: center;
}
.confirmMessage
{
color: #006400;
text-align: center;
}
.datebox
{
text-align:center;
}
</style>
<style type="text/css">
.CCSListBox
{
width: 200px;
}
</style>
</head>
<body style="margin-left: 20%; margin-right: 20%">
<form id="form1" runat="server">
<table class="SnapIn" style="text-align: center; height: 100%; border: 0; background-color: #FFFFFF; width: 100%;
border: 3px solid #6699CC" cellpadding="0" cellspacing="0">
<tr class="ToolsRow">
<td class="Title" style="white-space: nowrap; width=20%">
Pubblicazione Report
</td>
<td style="width: 80%; text-align: right">
</td>
</tr>
<tr style="height: 5%">
<td colspan="2">
</td>
</tr>
<tr style="text-align: center;">
</tr>
<tr style="height: 15%">
<td colspan="2">
</td>
</tr>
<tr>
<td style="text-align: center" colspan="2">
<div style="text-align:center">
<b>Scegliere il nome del report * </b>
<asp:DropDownList id="dropdownlist1" style="width:250px;" runat="server"></asp:DropDownList>
<br />
<br />
<br />
<b>Scegliere la data del report </b>
<asp:TextBox runat="server" ID="txtSchedDate" name="txtSchedDate" type="text" cssclass="datebox" style="height:20px;" ReadOnly="true"/>
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Pubblica" OnClientClick="show_table();" OnCommand="Button1_Click" />
<br />
<br />
<br />
<br />
<asp:Label ID="Label1" Font-Names="Arial" Font-Size="15px" runat="server" ForeColor="Red" Font-Bold="True" Text=""></asp:Label>
<div id="divUpload" style="display:none">
<div style="width:200pt;;text-align:center;">Pubblicando...</div>
</div>
</div>
</td>
<br/>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<br />
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<br />
<table width="100%" id="tbnotification" class="Stripy" style="display:block;">
<tr>
<tr>
<td colspan="2" style="text-align: center">
<asp:Label ID="tbnotif" runat="server" ReadOnly="True" Text="" >
</asp:Label>
</td>
</tr>
<tr>
<td>
<asp:GridView ID="gwreportpub" runat="server" CellPadding="5" BorderStyle="Solid" OnRowDataBound="coloraRighe" AllowPaging="true" PageSize="15" OnPageIndexChanging="GridView1_PageIndexChanging" style="border: 1px solid black;">
</asp:gridview>
</td>
</tr>
</tr>
</table>
</td>
</tr>
</table>
</form>
<script type="text/javascript">
var dpck_1 = new DatePicker({ relative: 'txtSchedDate', language: 'it' });
</script>
ok did an external client in java and i did produce a jar that call the webservice
after i did this for call the webserice inside the aspx page:
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.FileName = "\"" + System.Web.HttpContext.Current.Server.MapPath(".") + "\\" + "ConsoleApp.jar" + "\"" ;
if(datarepo != "")
proc.StartInfo.Arguments = "\""+connectionString +"\"" + " " +"\"" +reportname+"\"" + " " +"\"" +datarepo+"\"" + " " +"\"" +opco+"\"" + " " + "\"" +ambienteParm+"\"";
else
proc.StartInfo.Arguments = "\""+connectionString +"\"" + " " +"\"" +reportname+"\"" + " " +"\"" + "\"" + " " +"\"" +opco+"\"" + " " + "\"" +ambienteParm+"\"";
proc.Start();
proc.WaitForExit();
//string result = proc.StandardOutput.ReadToEnd();
//Response.Write(result + " - " + proc.ExitCode);
proc.Close();
thxs to everyone.

When using radio button,I'm tring to hide div, the checkbox list[control itself] is not displayed

script:
$(document).ready(function () {
$('#Custom').hide('fast');
$('#rbtnEntire').click(function () {
$('#Custom').hide('fast');
$('#Entire').show('fast');
});
$('#rbtnCustom').click(function () {
$('#Entire').hide('fast');
$('#Custom').show('fast');
});
});
function showdiv() {
document.getElementById("divChkList").style.display = "block";
}
aspx file:
<div style="height:700; width:500;">
<div id="select scan type">
<asp:RadioButton ID="rbtnEntire" runat="server" Text="Entire"
GroupName="s1"/>
<asp:RadioButton ID="rbtnCustom" runat="server" Text="Custom"
GroupName="s1"/>
</div>
<div id="Entire" style="float:left; height:1000; width:1000; border: solid 1px; margin-left:5px;">
Entire<br />
<asp:TreeView ID="TreeView1" runat="server" ShowCheckBoxes="All" ShowLines="True" ExpandDepth="2">
<Nodes>
<asp:TreeNode Text="Entire">
<asp:TreeNode Text="VM">
<asp:TreeNode Text="MBS1">
</asp:TreeNode>
<asp:TreeNode Text="PF1"></asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="VM1">
<asp:TreeNode Text="MBS2"></asp:TreeNode>
<asp:TreeNode Text="PF2"></asp:TreeNode>
</asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
<p>
<asp:Button ID="btnCreateXML" runat="server" onclick="btnCreateXML_Click"
Text="Create XML" />
<asp:Label ID="lblResult" runat="server" Text="Label"></asp:Label>
</p></div>
<div id="Custom" style="float:left; height:1000; width:2000; border: solid 1px; margin-left:10px;">
Custom <br />
<div id="Manual" style="border:solid 1px; float:left;">
Manual Scan Controls
</div>
<div id="Multiple" style="border:solid 1px; float:left;">
Multiple Scan Controls
<table>
<tr>
<td valign="top" style="width: 165px">
<asp:PlaceHolder ID="phDDLCHK" runat="server"></asp:PlaceHolder>
</td>
<td valign="top">
<asp:Button ID="btn" runat="server" Text="Get Checked" OnClick="btn_Click" />
</td>
<td valign="top">
<asp:Label ID="lblSelectedItem" runat="server"></asp:Label>
</td>
</tr>
</table>
</div>
<asp:HiddenField ID="hidList" runat="server" />
</div>
<br />
</div>
code behind:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
initialiseCheckBoxList();
rbtnEntire.Checked = true;
try
{
TreeView1.Attributes.Add("onclick", "javascript: OnTreeClick();");
}
catch(Exception)
{
Response.Write("Error Occured While onTreeClick");
}
}
}
public void initialiseCheckBoxList()
{
CheckBoxList chkBxLst = new CheckBoxList();
chkBxLst.ID = "chkLstItem";
chkBxLst.Attributes.Add("onmouseover", "showdiv()");
DataTable dtListItem = GetListItem();
int rowNo = dtListItem.Rows.Count;
string lstValue = string.Empty;
string lstID = string.Empty;
for (int i = 0; i < rowNo - 1; i++)
{
lstValue = dtListItem.Rows[i]["Value"].ToString();
lstID = dtListItem.Rows[i]["ID"].ToString();
chkBxLst.Items.Add(lstValue);
}
System.Web.UI.HtmlControls.HtmlGenericControl div = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
div.ID = "divChkList";
div.Controls.Add(chkBxLst);
div.Style.Add("border", "black 1px solid");
div.Style.Add("width", "160px");
div.Style.Add("height", "130px");
div.Style.Add("overflow", "AUTO");
div.Style.Add("display", "block");
}//end of initialiseCheckBoxList()
protected void btn_Click(object sender, EventArgs e)
{
string x=string.Empty;
string strSelectedItem = "Selected Items ";
CheckBoxList chk = (CheckBoxList)phDDLCHK.FindControl("chkLstItem"); // phDDLCHK is placeholder's ID
for (int i = 0; i < chk.Items.Count; i++)
{
if (chk.Items[i].Selected)
{
if (strSelectedItem.Length == 0)
{
strSelectedItem = strSelectedItem + ":" + chk.Items[i].Text;
}
else
{
strSelectedItem = strSelectedItem + ":" + chk.Items[i].Text;
}
}
}
lblSelectedItem.Text =strSelectedItem;
}
public DataTable GetListItem()
{
DataTable table = new DataTable();
table.Columns.Add("ID", typeof(int));
table.Columns.Add("Value", typeof(string));
for (int icnt = 0; icnt < 10; icnt++)
{
table.Rows.Add(icnt, "ListItem"+":"+icnt);
}
return table;
}
Problem: When i Select radio button rbtnCustom, It should display div Custom along with the CheckboxList control,which is not happening. When I do not hide div,it is displayed. What can be done to display checkboxList control?
Here is my code, Can any one let me know where I went wrong?
Any help would be appriciated! Thanks!
The reason some of your Javascript isn't working is because you are using the server ID in the client side (Javascript) code.
<asp:RadioButton ID="rbtnCustom" runat="server" Text="Custom"
GroupName="s1"/>
Since the above control is set to runat="server" the ID attribute is setting a sever side control ID, the client ID will be generated. If you don't need access to this control on the server, it might be easier to simply use a 'input' element instead of an asp.net control. The other option would be to set the ClientIDMode="Static" so the client ID is the same as the server ID.
<asp:RadioButton ID="rbtnCustom" runat="server" Text="Custom" ClientIDMode="Static"
GroupName="s1"/>
Use this for any control if you are not setting the ID in the code behind and if you are using the ID in client side Javascript.
EDIT: You are also missing phDDLCHK.Controls.Add(div); at the end of your initialiseCheckBoxList method.
You are also not providing what javascript "OnTreeClick();" is. It is referenced in the code behind. From what I can tell you are only populating the contents of the custom checkboxlist once on the initialiseCheckBoxList.
How to use asp checkbox control as RadioButton
First we create a script like this:
<script type="text/javascript">
function check(sender) {
var chkBox;
var i;
var j;
for (i = 1; i < 6; i++) {
for (j = 1; j < 6; j++) {
if (i != j) {
if (sender.id == "ck" + i) {
chkBox = document.getElementById("ck" + j);
}
else {
chkBox = document.getElementById("ck" + i);
}
if (sender.checked) {
if (chkBox.checked) {
chkBox.checked = false;
}
}
}
}
}
}
</script>
Now we use following code for our ASP CheckBox controls
<div>
<asp:CheckBox ID="ck1" runat="server" Text="P1" onclick="check(this)"/>
<asp:CheckBox ID="ck2" runat="server" Text="P2" onclick="check(this)"/>
<asp:CheckBox ID="ck3" runat="server" Text="P3" onclick="check(this)"/>
<asp:CheckBox ID="ck4" runat="server" Text="P4" onclick="check(this)"/>
<asp:CheckBox ID="ck5" runat="server" Text="P5" onclick="check(this)"/>
</div>
Thank you...

Resources