|
One way I think you could do it, is to have a dropdownlist in which they choose their role i.e. which client they are and then depending on that you assign the correct connection string for the option chosen in the dropdownlist.
does that make sense?
We are not a Code Charity
|
|
|
|
|
Hi Friends,
I m doing crystal report in asp.net2.0 using c#,i have written the code for crystal report dynamically getting the database connection from web.config file and i have created the crystal report manually making the database connection mapping the stored procedure.I m getting the output correctly.The problem is if i need to change the database server name means i should change only in web.config file,but i have given the connection for crystal report in code behind and crystal report manually.When i change the database server name in web.config file its not getting the effect only when i connect crystal report manually its getting connected.Sorry for long comments here is the coding for database connection.Please help me to solve the solution
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
string from = "";
string id = "";
string to = "";
string mode = "";
from =Request.QueryString["FromDate"];
id = Request.QueryString["id"];
to = Request.QueryString["toDate"];
mode =Request.QueryString["mode"];
ReportDocument rd = new ReportDocument();
rd.Load(Server.MapPath("TourOperator.rpt"));
rd.SetParameterValue(0, mode);
rd.SetParameterValue(1, id);
rd.SetParameterValue(2, from);
rd.SetParameterValue(3, to);
GetServerName(rd);
Session["torRep"] = rd;
foreach (CrystalDecisions.CrystalReports.Engine.ReportObject obj in rd.ReportDefinition.ReportObjects)
{
if (obj.Name == "txtfromdate")
{
((TextObject)obj).Text = from;
}
if(obj.Name=="txttodate")
{
((TextObject)obj).Text = to;
}
}
if (rd.Rows.Count > 0)
{
CrystalReportViewer1.Visible = true;
CrystalReportViewer1.ReportSource = rd;
CrystalReportViewer1.DataBind();
}
else
{
CrystalReportViewer1.Visible = false;
ltl.Text = "<b><font color='red'>No Records Found</font></b>";
}
}
else
{
CrystalReportViewer1.ReportSource = (ReportDocument)Session["torRep"];
CrystalReportViewer1.DataBind();
}
}
private void GetServerName(ReportDocument rep)
{
try
{
ConnectionInfo cinfo = new ConnectionInfo();
TableLogOnInfo tinfo = new TableLogOnInfo();
string cStr = ConfigurationManager.ConnectionStrings["sqlcon"].ConnectionString;
cinfo.ServerName = cStr.Split(';')[0].Split('=')[1];
cinfo.DatabaseName = cStr.Split(';')[3].Split('=')[1];
cinfo.UserID = cStr.Split(';')[1].Split('=')[1];
cinfo.Password = cStr.Split(';')[2].Split('=')[1];
foreach (CrystalDecisions.CrystalReports.Engine.Table objTable in rep.Database.Tables)
{
tinfo = objTable.LogOnInfo;
tinfo.ConnectionInfo = cinfo;
objTable.ApplyLogOnInfo(tinfo);
}
}
catch (Exception ex)
{
throw ex;
}
}
Thanks in Advance
|
|
|
|
|
Hello Friends,
Error: I am not able to load the image on the page every time I get an Red X mark
Question: Can anyone help me identifying the error from the code that I am using to retrieve the image from the SQLSERVER2005 on to an ASP.NET PAGE in C#
Code for DisplayPhoto.aspx.cs:
protected void Page_Init(object sender, EventArgs e)
{
SqlConnection SqlConnection1 = new SqlConnection();
string connstring = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlConnection1.ConnectionString = connstring;
SqlConnection1.Open();
if (Request.QueryString["id"] != null)
{
int id;
if (Int32.TryParse(Request.QueryString["id"], out id))
{
Response.Clear();
Response.ContentType = "image/jpeg";
System.Drawing.Image image1 = RetrieveImage(id);
image1.Save(Response.OutputStream, ImageFormat.Jpeg);
}
}
}
private System.Drawing.Image RetrieveImage(int photoId)
{
System.Drawing.Image image2 = null;
System.Data.SqlClient.SqlCommand cmd_selectphoto = new System.Data.SqlClient.SqlCommand();
cmd_selectphoto.Connection = SqlConnection1;
cmd_selectphoto.CommandType = CommandType.Text;
cmd_selectphoto.CommandText = "SELECT PhotoImage FROM Photo WHERE PhotoID = 5";
//cmd_selectphoto.Parameters.AddWithValue("3", photoId);
byte[] imageData = (byte[])cmd_selectphoto.ExecuteScalar();
MemoryStream memStream = new MemoryStream(imageData);
image2 = System.Drawing.Image.FromStream(memStream);
return image2;
}
Code for DisplayPhoto.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DisplayPhoto.aspx.cs" Inherits="DisplayPhoto" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<%-- <link href="Admin.css" type="text/css" rel="stylesheet" />--%>
<title>Display Photo</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<center>
<table width="80%" style="height: 62px" cellspacing="0" cellpadding="0" border="0"
class="table">
<tr>
<td>
<asp:Image ID="image1" runat="server" />
</td>
</tr>
</table>
</center>
</div>
</form>
</body>
</html>
|
|
|
|
|
To load an image, you need a file on disc. Or, you need to write a HTTP handler that returns the byte data, passing the image Id on the URL.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi Christian,
I have a file on the disc and that code works perfectly. .I am able to load the image in the SQL SERVER2005. . My Question here is how to retrieve the image from SQL SERVER2005. I have used the code as mentioned if you can help me in identifying the error it would be so nice. .
|
|
|
|
|
Hi All,
Can any one tell me, how do we idenify that the database whose we are connected in a web application is MySql, SQL Express, .. etc.
Thanks in advance for solving my problem...
Brijendra
|
|
|
|
|
Hello,
I try to explain as best as I can what I'm trying to do:
1)I'm writing a web app using ASP.NET / FW 3.5 and LINQ to SQL.
2)I've got a table called Categories {id<pk>, description} and SubCategories {id<pk>,parentid<pk>, description}
3)I've got two gridview binded to the tables above with LinqDataSource (tried with a single data source and 2 different one)
Even if on db there's a relationship between Categories and SubCategories I can't find an easy way to have the second gridview (the subcategories one) binded to the first one. right now I'm doing the "binding" between the two manually, getting the selected row from first and digging to get the id, but I don't like it much, since sometimes category grid view loses the selectedrow property.
Is somewere an example or tutorial about how can I do it in the best way?
Thanks
Bests
|
|
|
|
|
Hi,
I created one dropdownlist dynamically,when i select any value in that dynamically created dropdownlist,i have to create one more dropdownlist and based on the value of first dropdown,i m going to input respective items in the second dropdown list.i have to continue the same for 2 more dropdown.
i just tried by using the following code:
list.SelectedIndexChanged += new EventHandler(list_SelectedIndexChanged);
but this event is not getting fired at all.
can anybody please help me to resolve this issue.
Regards
Vidhya
|
|
|
|
|
You should try the following ajax tool, it might apply to your situation
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/CascadingDropDown/CascadingDropDown.aspx
We are not a Code Charity
|
|
|
|
|
vidhyap wrote: I created one dropdownlist dynamically
You should be aware of how controls and it's viewstate works. How you are creating dynamic control ? If you are doing that in page_load or any other control's events, ASP.NET won't maintain viewstate for that control. AFAIK, Init is a perfect place for creating dynamic controls. If you are creating the dynamic controls inside a gridview/datagrid, this won't be a problem though.
vidhyap wrote: list.SelectedIndexChanged += new EventHandler(list_SelectedIndexChanged);
Looks fine. Have you set Autopostback=true ?
|
|
|
|
|
Hi Navaneeth,
Thanks for ur reply,I m not creating dropdownlist in page load.
I am creating dynamic dropdownlist based on the value of another dropdown list.
I can't create the dropdown in pageload because the condition is whenever user selects some value in first dropdown then only based on that value I am going to create differnt number of dropdowns.
I tried setting Autopostback=true.then also that event is not getting triggered.can you please help me to solve this issue.
Regards
Vidhya
|
|
|
|
|
vidhyap wrote: selects some value in first dropdown then only based on that value I am going to create differnt number of dropdowns.
So in that dropdowns selected index changed event you are creating another control and showing, right ? Can you post that code ?
|
|
|
|
|
what exactly I am doing is,based on selected value of first dropdownlist value,I am creating different number of dropdownlist box dynamically.
below code is for selected indexchanged for first dropdown:
protected void ddlSurveyName_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlSurveyName.SelectedItem.Text != "Select")
{
int surveyIdentity = Convert.ToInt32(ddlSurveyName.SelectedValue);
lblErrorSurveyName.Visible = false;
ISession session = NHibernateSessionManager.Instance.GetSession();
IQuery surveyAttributeQry = session.CreateQuery("from SurveyAttributeEntity se where SurveyID='" + surveyIdentity + "'");
IList surveyAttributeList = surveyAttributeQry.List();
foreach (SurveyAttributeEntity surveysAttributeEn in surveyAttributeList)
{
int surveyId = Convert.ToInt32(surveysAttributeEn.SurveyID);
int attributeId = Convert.ToInt32(surveysAttributeEn.AttributeID);
createddl(surveyId, attributeId);
}
}
else
{
lblErrorSurveyName.Visible = true;
lblErrorSurveyName.Text = Resources.VP_THAI.lblErrorSurveyName;
}
ddlExportTo.Enabled = false;
}
and later i have to check for hierarchy dropdownlist box,if it is created dynamically,based on the value of this Hierarchy dropdownlist i have to create one more dropdownlist and depending on the selected value of newly created dropdownlist i am going to create one more.
code i am using to create dynamic dropdownlist is as below:
protected void createddl(int surveyID, int attributeID)
{
ISession session = NHibernateSessionManager.Instance.GetSession();
IQuery attributeValueQry = session.CreateQuery("from MasterValueEntity mve where TypeID='" + attributeID + "'");
IList attributeValueList = attributeValueQry.List();
IQuery labelValueQry = session.CreateQuery("from MASTERTYPEEntity mte where TypeID='" + attributeID + "'");
IList labelValueList = labelValueQry.List();
IQuery hierarchyValueQry = session.CreateQuery("from HierarchyEntity hierarchentity where Level="+1);
IList hierarchyValueList = hierarchyValueQry.List();
DropDownList list = new DropDownList();
CheckBox chkAndAbove = new CheckBox();
list.Items.Add("Select");
Label label1 = new Label();
if (attributeID == 0)
{
label1.Text = "Hierarchy";
label1.Width = Unit.Percentage(60);
label1.Height = Unit.Percentage(50);
list.ID = "Hierarchy";
list.AppendDataBoundItems = true;
list.Width = Unit.Percentage(65);
list.Items[0].Text = "Select";
list.Items[0].Value = "-1";
list.Items[0].Selected = true;
list.DataValueField = "Id";
list.DataTextField = "Hname";
list.DataSource = hierarchyValueList;
list.DataBind();
list.AutoPostBack = true;
list.SelectedIndexChanged += new EventHandler(list_SelectedIndexChanged);
chkAndAbove.Text = "And Above";
}
else
{
foreach (MASTERTYPEEntity masterTypeEn in labelValueList)
{
list.ID = masterTypeEn.TypeName;
label1.Text = masterTypeEn.TypeName;
label1.Width = Unit.Percentage(60);
label1.Height = Unit.Percentage(50);
}
list.AppendDataBoundItems = true;
list.Width = Unit.Percentage(65);
list.Items[0].Text = "Select";
list.Items[0].Value = "-1";
list.Items[0].Selected = true;
list.DataValueField = "Id";
list.DataTextField = "TypeDesc";
list.DataSource = attributeValueList;
list.DataBind();
}
PlaceHolder1.Controls.Add(label1);
PlaceHolder2.Controls.Add(list);
PlaceHolder2.EnableViewState = true;
session.Close();
NHibernateSessionManager.Instance.CloseSession();
}
now can you give me any suggestion to proceed on the same.
Regards
Vidhya
|
|
|
|
|
Ok. it's a viewstate issue. Dynamic controls should be created each time when page refreshes. So Init is the best event for doing this. In init event, control's data won't be initialized, but it will be available with the Request.Form collection. So you have to read the value from there, do checking and create your controls. Keep it in mind, init event is too early in the page life cycle and you won't get values from the control's properties. Look into the Request.Form instead.
|
|
|
|
|
Hi Navaneeth,
Thanks for ur reply.hey I just want to confirm one thing in page_init method can I use Request.Form so that i can get the value of dynamically created dropdownlist and fire the selectedindexchanged event for the same.
Regards
Vidhya
|
|
|
|
|
vidhyap wrote: I just want to confirm one thing in page_init method can I use Request.Form so that i can get the value of dynamically created dropdownlist and fire the selectedindexchanged event for the same.
yes. it will do
|
|
|
|
|
Set the AutoPostBack property to true for the control (here dropdownlist) which wants to communitcate with the web server.
|
|
|
|
|
I did that,but then also that selectedIndexChanged event is not getting fired.
As Navaneeth said there is an issue with viewstate itself.i don't know how to solve this problem.
Regards
Vidhya
|
|
|
|
|
i use ajaxToolkit:modalpopupExtender in my site..its working fine on local machine...but when i upload this site on net i got this exception..
"Could not load file or assembly 'AjaxControlToolkit' or one of its dependencies. The system cannot find the file specified."...so please tell me the solution..as i copied all dll.."AjaxControlToolkit.dll","System.Web.Extensions.dll","AJAXExtensionsToolbox.dll","System.Web.Extensions.Design.dll" and some other folder in bin folder.....please help me
|
|
|
|
|
Have you added it to your toolbar in visual studio?
Have you delcared the tag AjaxControlToolkit at the top of the page?
We are not a Code Charity
|
|
|
|
|
ya i have added this in my master page...
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
its working fine on my local server..but on net its giving the exception...Could not load file or assembly 'AjaxControlToolkit' or one of its dependencies. The system cannot find the file specified....please help me
|
|
|
|
|
Server has "AJAX extensions" installed ?
|
|
|
|
|
You need to make sure ajax is installed on your server as well as your localmachine
We are not a Code Charity
|
|
|
|
|
No ajax is not installed on server....is der any other way to run the site without installing the ajax on server.....cann't it run only by copying the dll on bin folder....please tell if der is any other way....
|
|
|
|
|
Nope I'm pretty sure you have to have ajax installed on the server because that is where the code is going to be running and it needs to know what the control is.
Its not hard to install on the server, is there any reason why your hesitant?
We are not a Code Charity
|
|
|
|