I am binding data from a dataset to a grid and exporting data from the grid to an excel.if the the number of items in the grid is greater than 50000,an error message is displayed.
So i want to split the data and display it in different worksheets in excel.(Am working in a web application)
using this code for exporting to excel
gvExcel.DataSource = DTS;
gvExcel.DataBind();
Response.AddHeader("content-disposition", "attachment; filename= filename.xls");
Response.ContentType = "application/excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gvExcel.RenderControl(htw);
// Style is added dynamically
Response.Write(style);
Response.Write(sw.ToString());
Response.End();
Can anyone help me on this??
I'm using AJAX_POSTUP. When i make a request it sends a file to a bowser [offers to download] (the files content are params of the action methods). Does anyone know whats going on and how i can avoid this problem???
i'm not aware of other plugins such as AJAX_POSTUP
When compiling this code:
public class WindsorControllerFactory : IControllerFactory
{
private readonly WindsorContainer _container;
public WindsorControllerFactory(WindsorContainer container)
{
_container = container;
}
public IController CreateController(RequestContext requestContext,
string controllerName)
{
return (IController)_container.Resolve(controllerName);
}
public void ReleaseController(IController controller)
{
_container.Release(controller);
}
}
I am getting this error:
'WindsorControllerFactory' does not
implement interface member
'System.Web.Mvc.IControllerFactory.CreateController(System.Web.Routing.RequestContext,
string)'
Well, it obviously implements this member. Has anyone encountered this problem?
I'm passing data using .ajax and here are my data and contentType attributes:
data: '{ "UserInput" : "' + $('#txtInput').val() + '","Options" : { "Foo1":' + bar1 + ', "Foo2":' + Bar2 + ', "Flags":"' + flags + '", "Immunity":' + immunity + '}}',
contentType: 'application/json; charset=utf-8',
Server side my code looks like this:
<WebMethod()> _
Public Shared Function ParseData(ByVal UserInput As String, ByVal Options As Options) As String
The userinput is obvious but the Options structure is like the following:
Public Structure Options
Dim Foo1 As Boolean
Dim Foo2 As Boolean
Dim Flags As String
Dim Immunity As Integer
End Structure
Everything works fine when $('#txtInput') contains no double-quotes but if they are present I get an error (for an input of asd"):
{"Message":"Invalid object passed in, \u0027:\u0027 or \u0027}\u0027 expected. (22): { \"UserInput\" : \"asd\"\",\"Options\" : { \"Foo1\":false, \"Foo2\":false, \"Flags\":\"\", \"Immunity\":0}}","StackTrace":" at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeDictionary(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.ArgumentException"}
Any idea how I can avoid this error? Also, when I pass the same input with quotes directly it works fine.
I have a gridview with edit option at the start of the row. Also I maintain a seperate table called Permission where I maintain user permissions. I have three different types of permissions like Admin, Leads, Programmers. These all three will have access to the gridview. Except admin if anyone tries to edit the gridview on clicking the edit option, I need to give an alert like This row has important validation and make sure you make proper changes.
When I edit, the action with happen on table called Application. The table has a column called Comments. Also the alert should happen only when they try to edit rows where the Comments column have these values in them.
ManLog datas
Funding Approved
Exported Applications
My try so far.
public bool IsApplicationUser(string userName)
{
return CheckUser(userName);
}
public static bool CheckUser(string userName)
{
string CS = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
DataTable dt = new DataTable();
using (SqlConnection connection = new SqlConnection(CS))
{
SqlCommand command = new SqlCommand();
command.Connection = connection;
string strquery = "select * from Permissions where AppCode='Nest' and UserID = '" + userName + "'";
SqlCommand cmd = new SqlCommand(strquery, connection);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
}
if (dt.Rows.Count >= 1)
return true;
else
return true;
}
protected void Details_RowCommand(object sender, GridViewCommandEventArgs e)
{
string currentUser = HttpContext.Current.Request.LogonUserIdentity.Name;
string str = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
string[] words = currentUser.Split('\\');
currentUser = words[1];
bool appuser = IsApplicationUser(currentUser);
if (appuser)
{
DataSet ds = new DataSet();
using (SqlConnection connection = new SqlConnection(str))
{
SqlCommand command = new SqlCommand();
command.Connection = connection;
string strquery = "select Role_Cd from User_Role where AppCode='PM' and UserID = '" + currentUser + "'";
SqlCommand cmd = new SqlCommand(strquery, connection);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
}
if (e.CommandName.Equals("Edit") && ds.Tables[0].Rows[0]["Role_Cd"].ToString().Trim() != "ADMIN")
{
int index = Convert.ToInt32(e.CommandArgument);
GridView gvCurrentGrid = (GridView)sender;
GridViewRow row = gvCurrentGrid.Rows[index];
string strID = ((Label)row.FindControl("lblID")).Text;
string strAppName = ((Label)row.FindControl("lblAppName")).Text;
Response.Redirect("AddApplication.aspx?ID=" + strID + "&AppName=" + strAppName + "&Edit=True");
}
}
}
Kindly let me know if I need to add something. Thanks for any suggestions.
Is it possible to instruct the aspnet_compiler to set debug=false in the web.config?
My intention is to automate this as part of the nant build process. I am open to suggestions other than xml parsing
Hi,
I'm trying to access the values a user introduces in a table from my controller.
This table is NOT part of the model, and the view source code is something like:
<table id="tableSeriales" summary="Seriales" class="servicesT" cellspacing="0" style="width: 100%">
<tr>
<td class="servHd">Seriales</td>
</tr>
<tr id="t0">
<td class="servBodL">
<input id="0" type="text" value="1234" onkeypress = "return handleKeyPress(event, this.id);"/>
<input id="1" type="text" value="578" onkeypress = "return handleKeyPress(event, this.id);"/>
.
.
.
</td>
</tr>
</table>
How can I get those values (1234, 578) from the controller?
Receiving a formcollection doesn't work since it does not get the table...
Thank you.
Hi,
I am interested in writing unit tests for the SharePoint development work I am doing. Can anyone suggest practical approachs to implementing unit tests in MOSS?
Note that any third party tools have to be free (but not necessarily open-source); the company I work for will not pay for additional tooling. In particular, any alternatives to the Typemock Isolator for SharePoint would be appreciated.
Thanks, MagicAndi.
I have a web app that is using the 3.5 framework. I wanted to know how can I detect what webhost is rendering the page.
If the server is localhost, then send email notification to [email protected]
If the server is QA, then send email to [email protected]
Thanks
I'm tying to use one database call and reuse that data for other controls - without having to do another call. Scenario: I call the books table which returns all the authors and titles. I create an author's list control called list1 to displays all the titles by Shakespeare and a list2 to display titles by Charles Dickens.
Void Bindme()
{
string commandText = "Select * from books";
SqlCommand mycommand = new SqlCommand(commandText, datasource1);
datasource1.Open();
SqlDataReader myReader1 = mycommand.ExecuteReader();
list1.DataSource = myReader1;
list1.DataBind();
list2.DataSource = myReader1;
list2.DataBind();
datasource1.Close();
}
In my example only the first bind to the source, list1, gets data. Any ideas?
I want to access all the files in a folder to add to a listbox and show to the user.
I know I can access a folder when it's a windows application. But in web application, is this possible? If yes, how?
Something like FolderBrowserDialog??
I've been playing with MVC 3 in a test project and have the following issue.
I have Group & Subscriber entities and those are coupled through a SubscriberGroup table.
Using the DetailView of Group I open a view of SubscriberGroup containing all subscribers.
This list has the option to filter.
So far it all works, however when I call the AddToGroup method on the controller it fails. Specifically it goes into the method but doesn't pass the subscriberCheckedModels list.
Am I doing something wrong?
View: SubscriberGroup Index.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.master" Inherits="System.Web.Mvc.ViewPage<Mail.Models.SubscriberCheckedListViewModel>" %>
…
<h2 class="common-box-title">
Add Subscribers to Group</h2>
<p>
<% using (Html.BeginForm("Index", "SubscriberGroup"))
{ %>
<input name="filter" id="filter" type="text" />
<input type="submit" value="Search" />
<%} %>
</p>
<% using (Html.BeginForm("AddToGroup", "SubscriberGroup", Model,FormMethod.Get, null))
{ %>
<fieldset>
<div style="display: inline-block; width: 70%; vertical-align: top;">
<% if (Model.subscribers.Count() != 0)
{ %>
<table class="hor-minimalist-b">
<tr>
<th>
Add To Group
</th>
<th>
Full Name
</th>
<th>
Email
</th>
<th>
Customer
</th>
</tr>
<% foreach (var item in Model.subscribers)
{ %>
<tr>
<td>
<%= Html.CheckBoxFor(modelItem => item.AddToGroup)%>
</td>
<td>
<%= Html.DisplayFor(modelItem => item.subscriber.LastName)%>
<%= Html.ActionLink(item.subscriber.FirstName + " " + item.subscriber.LastName, "Details", new { id = item.subscriber.SubscriberID })%>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.subscriber.Email)%>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.subscriber.Customer.Company)%>
<%= Html.HiddenFor(modelItem => item.subscriber) %>
</td>
</tr>
<% } %>
<% ViewBag.subscribers = Model.subscribers; %> probeersel
<%= Html.HiddenFor(model => model.subscribers) %> probeersel
</table>
<%} %>
<%else
{ %>
<p>
No subscribers found.</p>
<%} %>
<input type="submit" value="Add Subscribers" />
</div>
</fieldset>
<%} %>
Controller: SubscriberGroupController
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using Mail.Models;
namespace Mail.Controllers
{
public class SubscriberGroupController : Controller
{
private int groupID;
private MailDBEntities db = new MailDBEntities();
//
// GET: /SubscriberGroup/
public ActionResult Index(int id)
{
groupID = id;
MembershipUser myObject = Membership.GetUser();
Guid UserID = Guid.Parse(myObject.ProviderUserKey.ToString());
UserCustomer usercustomer = db.UserCustomers.Single(s => s.UserID == UserID);
var subscribers = from subscriber in db.Subscribers
where (subscriber.CustomerID == usercustomer.CustomerID) | (subscriber.CustomerID == 0)
select new SubscriberCheckedModel { subscriber = subscriber, AddToGroup = false };
SubscriberCheckedListViewModel test = new SubscriberCheckedListViewModel();
test.subscribers = subscribers;
return View(test);
}
[HttpPost]
public ActionResult Index(string filter)
{
MembershipUser myObject = Membership.GetUser();
Guid UserID = Guid.Parse(myObject.ProviderUserKey.ToString());
UserCustomer usercustomer = db.UserCustomers.Single(s => s.UserID == UserID);
var subscribers2 = from subscriber in db.Subscribers
where ((subscriber.FirstName.Contains(filter)|| subscriber.LastName.Contains(filter))
&& (subscriber.CustomerID == usercustomer.CustomerID || subscriber.CustomerID == 0))
select new SubscriberCheckedModel { subscriber = subscriber, AddToGroup = false };
SubscriberCheckedListViewModel test = new SubscriberCheckedListViewModel();
test.subscribers = subscribers2.ToList();
return View(test);
}
[HttpPost]
public ActionResult AddToGroup(SubscriberCheckedListViewModel test)
{
//test is null
return RedirectToAction("Details", "Group", new { id = groupID });
}
}
}
ViewModel: SubscriberGroupModel
using System.Collections.Generic;
using Mail;
namespace Mail.Models
{
public class SubscriberCheckedModel
{
public Subscriber subscriber { get; set; }
public bool AddToGroup { get; set; }
}
public class SubscriberCheckedListViewModel
{
public IEnumerable<SubscriberCheckedModel> subscribers { get; set; }
}
}
I have a bit of code that I have been tasked with converting to C# from VB. A snippet of mine seems like it cannot be converted from one to the other, and if so, I just don't know how to do it and am getting a little frustrated.
Here's some background:
OrderForm is an abstract class, inherited by Invoice (and also PurchaseOrder). The following VB snippet works correctly:
Dim Invs As List(Of OrderForm) = GetForms(theOrder.OrderID)
....
Dim inv As Invoice = Invs.Find(
Function(someInv As Invoice) thePO.SubPONumber = someInv.SubInvoiceNumber)
In C#, the best I came to converting this is:
List<OrderForm> Invs = GetForms(theOrder.OrderID);
....
Invoice inv = Invs.Find(
(Invoice someInv) => thePO.SubPONumber == someInv.SubInvoiceNumber);
However, I get the following error when I do this:
Cannot convert lambda expression to delegate type 'System.Predicate' because the parameter types do not match the delegate parameter types
Is there any way to fix this without restructuring my whole codebase?
I'd like to setup a RegularExpressionValidator to ensure users are entering valid windows IDs in a textbox.
Specifically, I'd like to ensure it's any three capital letters (for our range of domains), followed by a backslash, followed by any number of letters and numbers.
Does anyone know where I can find some examples of this type of validation...or can somebody whip one up for me? :)
Hi, I have a AdvWebGrid where the 7th coloumn is DynEdit where user will enter the value.Now I have to take the enetered value and insert into the Sql tablel. For example i have 7 records in the grid the user will enter some comments for the first three record and save.Now i have to insert/update the first three comments in the table.
How does one stream files, html or custom AJAX responses from web parts?
Our current quick-and-very-dirty solution is to make the web part call the current page with certain query parameters, which the web part checks and instead of performing normal load it writes the required things to output and calls response end.
This sounds bad since SharePoint might load other web parts and execute their code before reaching our web part.
The web part is configured with data source settings which means the streaming context must be specific to the web part so it can acquire the correct data source settings.
Hi I have a jqgrid which is embedded in a Div. I am deleting records from the grid and reloading the grid using grid.Trigger('reload').
The width of the grid is considerably high so it has a scroll bar. Now I scrolled through the end of the grid horizontally before deleting records. Each time I delete the records and reload the grid, the column headers and their values are slightly misaligned. When I move the scroll bar back to original position or just move the scroll bar slightly they are aligned properly.
So I thought its better to move the scroll bar to its inital position when the grid reloads. How can a scroll bar be programatically moved using javascript. Or is there any other way to solve my problem?
I have a third party tool that creates an img tag through code using HtmlTextWriter's RenderBeginTag, RenderEndTag & AddAttribute methods. I want to get the resulting HTML into a string.
I tried the reflection method mentioned here but I get a error "Unable to cast object of type 'System.Web.HttpWriter' to type 'System.IO.StringWriter". The InnerWriter type of the HtmlTextWriter is of type HttpWriter.
Any ideas on how to copy the output html into a string?
how to invisible a column in gridview.I tried to use this---dataGridView.Columns(0).Visible = False.But its getting an error "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index".How to do that?
Alright, so what i have, is a large string i need to parse, and what i need to happen, is find all the instances of extract"(me,i-have lots. of]punctuation, and store them to a list.
So say this piece of string was in the beginning and middle of the larger string, both of them would be found, and their index's would be added to the List. and the List would contain 0 and the other index whatever it would be.
Ive been playing around, and the string.IndexOf does almost what i'm looking for, and ive written some code. But i cant seem to get it to work:
List<int> inst = new List<int>();
int index = 0;
while (index < source.LastIndexOf("extract\"(me,i-have lots. of]punctuation", 0) + 39)
{
int src = source.IndexOf("extract\"(me,i-have lots. of]punctuation", index);
inst.Add(src);
index = src + 40;
}
inst = The list
source = The large string
Any better ideas?
Hello,
I'm having a problem with some reports in the application I'm doing manutention
I've a button that does a postback to the server and do some information and then get back to the cliente and open a popup to download the report.
private void grid_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
...
ClientScript.RegisterClientScriptBlock(this.GetType(), "xxx", "<script>javascript:window.location('xx.aspx?m=x','xxx','width=750,height=350,directories=no,location=no,menubar=no,scrollbars,status=no,toolbar=no,resizable=yes,left=50,top=50');</script>");
}
Then in xxx.aspx I've the code:
Response.ClearContent();
Response.ClearHeaders();
Response.TransmitFile(tempFileName);
Response.Flush();
Response.Close();
File.Delete(tempFileName);
Response.End();
This works fine if IE option Automatic prompting for file downloads is enabled. But by default this is disabled and I need to force the download box to be prompting.
Can I do anything without change a lot of code?
Thanks.
I've designed a multilingual web site and some values in database have a tag which will be replaced with it's language value, remove tags brackets ( in case {} ) or removed completely.
There are two cases:
Remove brackets:
value {mm} >> value mm
Remove completely:
value {mm} >> value
Also {tag} could be any length and can contain -
Can anybody help me with regex?