查看状态值到数据表 [英] Viewstatevalues to a Datatable
问题描述
是否将Viewstate值分配给数据表?
我有一个由一组记录组成的数据表.我已将此datatablerecords置于viewstate中,以便可以从同一页面上的其他方法访问它.
Assigning Viewstate Values To A Datatable?
I have a datatable which consists of a set of records. I have put this datatablerecords in a viewstate so that I can access it from a different method on the same page.
dt = TelephoneDtl.GetTelephoneData();
ViewState["CurrentPos"] = dt.Tables[2];
我现在希望将此视图状态值分配给数据表.像这样的东西:
I now want this view state values to be assigned to a datatable. Something like this:
datatable dt = ViewState["CurrentPos"];
我想对相同的逻辑进行清晰的编码
帮我...尽快
改善:
将选定的复选框值转换为PDF
我正在创建新的数据表,具有记录集.....我已将此数据表记录置于视图状态..以便检查循环条件...然后在循环中,我必须检查是否已选中复选框是否..... selected复选框值(使用id作为memberno)我必须将其传递给新的数据表....并使用renderhtml必须将其转换为PDF
帮助我
i want clear coding for the same logic
help me...as soon as possible
Improve:
Conversion of selected checkbox values into PDF
i am creating new datatable ,having set of records .....i have put this datatable records in a viewstate..in order to check for the looping condition ...then in for loop i have to check whether the checkbox is selected or not .....selected checkbox value(using id as memberno) i have to pass it to the new datatable ....and using renderhtml have to convert into PDF
HELP me
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string _strName = string.Empty;
_strName = "q";
//_strName = Request.QueryString["_strName"];
DataTable Print_Rep = new DataTable();
clsCompanySearch objRep_Cls = new clsCompanySearch();
Print_Rep = objRep_Cls.company_pdf(_strName);
Rpt_Company.DataSource = Print_Rep;
Rpt_Company.DataBind();
}
}
protected void Rpt_Company_Search_no_tabs_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
System.Web.UI.WebControls.Image img = (System.Web.UI.WebControls.Image)e.Item.FindControl("img_logo");
Label lbl_memberno = (Label)e.Item.FindControl("lblmemberno");
string memberno = lbl_memberno.Text.ToString().Trim();
//string image = HttpContext.Current.Server.MapPath("~/_Images/Arab_Logos/") + memberno.ToString() + ".jpg";
string image = HttpContext.Current.Server.MapPath("~/_Images/Arab_Logos/") + memberno.ToString() + ".jpg";
if (File.Exists(image))
{
img.ImageUrl = "~/_Images/Arab_Logos/" + memberno.ToString() + ".jpg";
img.Visible = true;
}
else
{
img.Visible = false;
}
//if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
//{
// CheckBox chk = new CheckBox();
// chk = e.Item.FindControl("");
// if (chk.Checked)
// {
// }
//}
}
//private void GetData()
//{
// DataTable dt = new DataTable();
// if (ViewState["SelectedRecords"] != null)
// dt = (DataTable)ViewState["SelectedRecords"];
// else
// dt = CreateDatatable();
// CheckBox chkall=(CheckBox)Rpt_Company.HeaderTemplate.
//}
//private DataTable CreateDatatable()
//{
// throw new NotImplementedException();
//}
protected void btnPDF_Click(object sender, EventArgs e)
{
try
{
DataTable dtData = new DataTable();
ViewState["Data"] = dtData;
DataTable dtResult = (DataTable)ViewState["Data"];
//dt.Columns.Add("Companyname",typeof(string));
//dt.Columns.Add("Location",typeof(string));
//dt.Columns.Add("Telephone",typeof(string));
//dt.Columns.Add("Email",typeof(string));
//dt.Columns.Add("Fax",typeof(string));
//dt.Columns.Add("web",typeof(string));
for (int i = 0; i < Rpt_Company.Items.Count; i++)
{
CheckBox ch = ((CheckBox)Rpt_Company.Items[i].FindControl("chkbox"));
if (ch.Checked == true)
{
DataRow dr = dtData.NewRow();
string[] memberno = { "1002", "1003","1006" };
//dr["Companyname"] = ((Label)Rpt_Company.Items[i].FindControl("Lbl_title1")).Text;
//CheckBox cbxIsActive = item.FindControl("chkbox") as CheckBox;
//HiddenField hdfID = item.FindControl("recordID") as HiddenField;
}
}
Rpt_Company.DataSource = dtData;
Rpt_Company.DataBind();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Omania.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
this.Page.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
//string path = HttpContext.Current.Server.MapPath("~/_Images/Arab_Logos/");
pdfDoc.Open();
try
{
HeaderFooter footer = new HeaderFooter(new Phrase("PAGE NUMBER:"), true)
{
Border = Rectangle.ALIGN_CENTER
};
pdfDoc.Footer = footer;
}
catch (Exception ex)
{
Paragraph paragraph = new Paragraph("Error! " + ex.Message);
paragraph.SetAlignment("center");
Chunk text = paragraph.Chunks[0] as Chunk;
if (text != null)
{
text.Font.Color = Color.RED;
}
pdfDoc.Add(paragraph);
}
StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
styles.LoadTagStyle("ol", "leading", "16,0");
styles.LoadTagStyle("li", "face", "garamond");
styles.LoadTagStyle("span", "size", "48px");
styles.LoadTagStyle("body", "font-family", "times new roman");
styles.LoadTagStyle("body", "font-size", "42px");
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
/* select items in checkboc*/
}
catch (Exception ex)
{
throw ex;
}
请帮助我
Please help me
推荐答案
尝试一下:
Try this:
DataTable dt = (DataTable) ViewState["CurrentPos"];
if (dt != null)
{
// Do what you need to do with the data table.
}
在此处阅读有关Viewstate的全部信息: MSDN:了解ASP.NET视图状态 [^ ]
简而言之,现在:
Read all about Viewstate here: MSDN: Understanding ASP.NET View State[^]
For now, in short:
dt = TelephoneDtl.GetTelephoneData();
// save data in viewstate
ViewState["CurrentPos"] = dt.Tables[2];
// Get data back from viewstate
DataTable dt = (DataTable)ViewState["CurrentPos"];
您只是缺少演员表
Hi ,
You are just missing casting
datatable dt = (DataTable)ViewState["CurrentPos"];
最好的问候
米特瓦里(M.Mitwalli)
Best Regards
M.Mitwalli
这篇关于查看状态值到数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!