Perhaps this will work for you.
var studentList = from s in context.Students
where s.id.Equals(1)
select s;
foreach(Student student in studentList)
{
Console.Write(student.id);
}
Cheers Disgyza Programmer Analyst
Perhaps this will work for you.
var studentList = from s in context.Students
where s.id.Equals(1)
select s;
foreach(Student student in studentList)
{
Console.Write(student.id);
}
Cheers Disgyza Programmer Analyst
Hi andiyuniar I've had this issue before. The way I handled it was to "spoof" a content page to change it's ContentType to display images. I would pass it an id via query string and then set the imageurl to the spoofed page. Here's an example that should help you. Please keep in mind, I don't know if it's the best solution, but it works for me. Also, there could be some performance hits if you have too many images being loaded on your page via this method. Create a WebForm... i called mine LoadImage.aspx Place this code in the Load event
if (Request.QueryString["Id"] != null)
{
int Id = Convert.ToInt32(Request.QueryString["Id"].ToString());
byte[] image = null;
//You will have to add your connection information and grab the image from the database
// ToDo: Load binary image into image variable;
if (image!=null)
{
MemoryStream ms = new MemoryStream(image);
Bitmap b = new Bitmap(Image.FromStream(ms));
Response.ContentType = "image/jpeg";
b.Save(Response.OutputStream, ImageFormat.Jpeg);
}
else
{
Bitmap b = new Bitmap(Image.FromFile(Server.MapPath("images/noimage.png")));
Response.ContentType = "image/jpeg";
b.Save(Response.OutputStream, ImageFormat.Jpeg);
}
}
else
{
Bitmap b = new Bitmap(Image.FromFile(Server.MapPath("images/noimage.png")));
Response.ContentType = "image/jpeg";
b.Save(Response.OutputStream, ImageFormat.Jpeg);
}
Then on the page you want to bind your image to just set the ImageUrl property to the webform plus query string.
Image1.ImageUrl = "LoadImage.aspx?Id=1";
Happy Coding
Cheers Disgyza Programmer Analyst
Hi Swetha, I got the results you were looking for. In my case this returns more than one instance. But it does work. Try using this
Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer mc = new Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer();
foreach (Microsoft.SqlServer.Management.Smo.Wmi.ServerInstance si in mc.ServerInstances)
{
Response.Write("ServerInstance: " + si.Name);
}
In my case it returns two instances MSSMLBIZ SQLEXPRESS
Cheers Disgyza Programmer Analyst
You should probably verify that there is only one ServerInstance being returned. Because you are using a foreach loop and overwriting the serverName value it will always show you the last ServerInstance. If you have more than one ServerInstance this may become a problem. Perhaps you can store the value of the ServerInstance in the Web.config file in the AppSettings? I'm heading home for the weekend and won't be able to check up on this post anymore until Monday. I wish you the best of luck Swetha. I'm sure you will find a solution.
Cheers Disgyza Programmer Analyst
There are several ways you can do this, each have pro's and con's. 1. You can query the database and return your records for each time the event handler fires. This can be an issue on performance if you have a lot of records being returned. (multiply this by each user using the system). 2. You can set up special queries to return only a set amount of records (only the data grid's page size) this is a better approach because it returns only the records you want to show the user. 3. You can save the information to ViewState, the ViewState stores information about the page using the browsers memory. It has more of a performance hit on the client, instead of the server. My suggestion if there are a lot of records would be to use option 2. I'm sure there are quite a few more ways in which this can be accomplished... the easiest way would be to just query the database each time the event fires... but this has performance issues. Try it out and see what works best for your situation. Best of luck,
Cheers Disgyza Programmer Analyst
I posted this on a different thread of yours but I figured I'd post it here as perhaps a different approach to your problem. I'm not entirely sure if this will work for you, but you can certainly give it a shot. You could try using this:
using(Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer m = new Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer())
{
foreach (ServerInstance si in mc.ServerInstances)
{
Response.Write("ServerInstance:" + si.Name + "
");
}
}
You'll probably have to add a Reference to Microsoft.SqlServer.Smo Best of luck
Cheers Disgyza Programmer Analyst
You could try using this:
using(Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer m = new Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer())
{
foreach (ServerInstance si in mc.ServerInstances)
{
Response.Write("ServerInstance:" + si.Name + "
");
}
}
You'll probably have to add a Reference to Microsoft.SqlServer.Smo Best of luck
Cheers Disgyza Programmer Analyst
Perhaps you need to create a new instance of your RegistryKey. Try the using key word
using(RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft SQL Server"))
{
String[] instances = (String[])rk.GetValue("InstalledInstances");
//Rest of your code goes here
}
Not entirely sure if that will work for you. Good luck
Cheers Disgyza Programmer Analyst
Check to ensure that there is data in your dataset. It could be that when you postback that your dataset is being wiped. Are you storing your currentList in the ViewState?
Cheers Disgyza Programmer Analyst
Maybe i'm missing something but my guess is you should rebind your DataGrid after the event fires. Example with your Edit Handler
protected void dgUserNote_EditCommand(object source, DataGridCommandEventArgs e)
{
dgUserNote.EditItemIndex = e.Item.ItemIndex;
BindData();
}
If you Re-Bind your DataGrid after all your commands are issued it should work fine for you. Best of luck,
Cheers Disgyza Programmer Analyst
Glad to hear it :)
Cheers Disgyza Programmer Analyst
You could store the data in an arraylist and store that arraylist in the ViewState similar to:
public ArrayList GetProductList
{
if(ViewState["ProductList"]==null)
{
ViewState["ProductList"] = new ArrayList();
}
return (ArrayList)ViewState["ProductList"];
}
public void AddProduct(int productId)
{
if(ViewState["ProductList"]==null)
{
ViewState["ProductList"] = new ArrayList();
}
((ArrayList)ViewState["ProductList"]).Add(productId);
}
Then when you want to add something to your product list you can call it using
AddProduct(productId);
And you can cycle through your ArrayList:
foreach(int productId in GetProductList().Items)
{
//execute code for productId
}
I'm not at my workstation at the moment, but this should help you get started on your problem. Best of luck!!! :)
Cheers Disgyza Programmer Analyst
Ok what i think you need to do is: Place the connection code in a new WebForm and then on the page that your showing your image set the image ImageUrl property to the new webform. E.g. Image.aspx is the new webform Image.aspx contains the new code listed in the post above. WebForm1.aspx is the page with your image Set the ImageUrl property to the new webform. Image.ImageUrl = "Image.aspx"; When the ImageUrl try to load it will load the new Image.aspx page. Since you are changing the ContentType it should load the page as an Image. Let me know if this works for you, if not i'm sure there are a ton of different ways to make this work for you. Best of luck!!! :-D
Cheers Disgyza Programmer Analyst
You could try something like this:
string query = "SELECT Image FROM TAB_Employee WHERE EmpID='" + EmpID + "'";
SqlCommand cmdImg = new SqlCommand(query, gCnn);
byte[] image = (byte[])cmdImg.ExecuteScalar();
MemoryStream mstream = new MemoryStream(image);
Bitmap bitmap = new Bitmap(System.Drawing.Image.FromStream(mstream));
Response.ContentType = "image/gif";
bitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
bitmap.Dispose();
Best of luck :)
Cheers Disgyza Programmer Analyst
If you put Session.Abandon(); in the page_load then that should do the trick. The only issue is that it will abandon the session everytime the user goes to that page. Not a big deal if it's on the Login page though. Hope this helps.
Cheers Disgyza Programmer Analyst
I'm not sure if this is what you meant but... Button.Attributes["onclick"] = "javascript:return confirm('Thank you for your submittion');"; Make sure you put that code in a place where a post back will occur otherwise the javascript won't get applied to the button onclick event. I'm not sure but you may be able to code that directly in the html source, instead of the code behind. Best of luck,
Cheers Disgyza Programmer Analyst
Hi, I'm not sure if this is what you are looking for but here goes. Tree Looks like this Tree Node 1 Tree Node 1 a Tree Node 1 b Tree Node 1b i Tree Node 1b ii Tree Node 1 c Lets say you want to hide Tree Node 1b ii TreeView.DataSource = SiteMapDataSource1; TreeView.DataBind(); TreeView.Nodes[0].ChildNodes[1].ChildNodes.RemoveAt(1); //This hides tree node 1b ii Hope this helps. Remember in order to do this you have to programatically bind the TreeView. Note remove the DataSourceID from the IDE first. Good luck
Cheers Disgyza Programmer Analyst
I don't think there is a way to draw the same control, but you can link the event handler of each submit button to one handler method.
sas9491 wrote:
the submit button is for the associated tab control
Then why again does it need to be on top? -- modified at 15:24 Friday 11th August, 2006
Cheers Disgyza Programmer Analyst
I think you are going to have to give a little more information on what you wish to accomplish in order for us to help you more. Where is the click event coming from? A linkbutton in the grid? or are you talking about adding a onclick event to a datacell?
Cheers Disgyza Programmer Analyst
Is this what you're looking for? DataGrid grid = new DataGrid(); //First Row BackColor grid.Items[0].BackColor = Color.Red; //First Row First Cell grid.Items[0].Cells[0].BackColor = Color.Green; As for changing the column's color I think you need to loop though each row for a particular cell and change the color that way... I'm not really sure if there is a better way to do it. e.g. //Change Column color for first cell foreach(DataRow row in grid.Rows) { row.Cells[0].BackColor = Color.Blue; }
Cheers Disgyza Programmer Analyst