get value from Linq and put it in the tex box - asp.net

i have this code
MasterSoapClient sp = new MasterSoapClient();
MasterData[] lstMasterData = sp.GetActivityType(stid, null, 1);
grdEditActivityType.DataSource = lstMasterData;
grdEditActivityType.DataBind();
Session["opType"] = 2;
txtActivityCode.Text = lstMasterData.ToString();
txtActivityCode.DataBind();
here i called web service and put all data in this Gridview "grdEditActivityType "
and already workin
but there is column of lstMasterData i want to put it in the text box out of the grid
how i can do this ?

txtActivityCode.Text is a Property that you can use to assign a text value to the TextBox.
If you use txtActivity.Text = " some input "; Your textbox will contain the text " some input ".
You don't need to Bind txtActivityCode afterwards.
Having this clarified the next step is to create the string you want using to assign to the text box.
string s = "";
foreach( var masterData in lstMasterData )
{
s += masterData.SomeProperty; // s += masterData.ToString(); maybe, it depends on what do you want to put in the textbox;
}
txtActivityCode.Text = s;
And that's all.
I would suggest to start look more over ASP.NET tutorials to understand better how this framework works.

Related

AppMaker - Navigate to Last Page on Table

Scenario:
I have a calculated SQL that returns 100 results.
Added a table (from this calculated SQL) and limited the size of the page by 25 results.
This will generate 4 pages.
Pager form AppMaker works well (navigates between pages) but i need a button that navigates directly from page 1 to the page 4.
is this possible?
Anyone got a solution for this?
Regards
If you need to know how many entries your table has (in your case it's seems fixed to 100, but maybe it could grow), you can still do what you want:
E.g. say your table on YOURPAGE depends on a datasource called Customers.
Create a new Data item called CustomerCount, with just one field, called Count (integer).
Its data source would be a sql query script:
Select count(CustomerName) as Count from Customers
on the page you are having the table on, add a custom property (say called
Count of type integer)
In the page attach event, set the property asynchronously with this custom action:
app.datasources.CustomerCount.load(function() {
app.pages.YOURPAGE.properties.Count = app.datasources.CustomerCount.count;
app.datasources.Customers.query.pageIndex = #properties.Count / 25;
app.datasources.Customers.datasource.load();
});
I tried similar things successfully in the past.
Found a solution for this:
ServerScript:
function CandidateCountRows() {
var query = app.models.candidate.newQuery();
var records = query.run();
console.log("Number of records: " + records.length);
return records.length;
}
in the button code:
var psize = widget.datasource.query.pageSize;
var pidx = widget.datasource.query.pageIndex;
var posicao = psize * pidx;
var nreg = posicao;
google.script.run.withSuccessHandler(function(Xresult) {
nreg = Xresult;
console.log('position: ' + posicao);
console.log('nreg: ' + nreg);
console.log('psize: ' + psize);
console.log('pidx: ' + pidx);
var i;
for (i = pidx; i < (nreg/psize); i++) {
widget.datasource.nextPage();
}
widget.datasource.selectIndex(1);
}).CandidateCountRows();
This will allow to navigate to last page.
If you know for a fact that your query always returns 100 records and that your page size will always be 25 records then the simplest approach is to make sure your button is tied to the same datasource and attach the following onClick event:
widget.datasource.query.pageIndex = 4;
widget.datasource.load();

Export ASPxGridView with column with multiline text to excel

Is it possible to export ASPxGridView with column which contains multiline text to excel using ASPxGridViewExporter?
I have an ASPxGridView with column that contains a multiline text.
When I export a grid's data using ASPxGridViewExporter that multiline text is rendered as one line (without line breaks).
I tried both <br/> and "\n" (newline) as line separators.
btw value of property PropertiesTextEdit-EncodeHtml is false on that column.
Thanks
There are 2 ways to achieve what you're looking for:
Specify WYSIWYG export type in XlsxExportOptionsEx:
XlsxExportOptionsEx options = new XlsxExportOptionsEx()
{
ExportType = DevExpress.Export.ExportType.WYSIWYG
};
ASPxGridView1.ExportToXlsx("Test.xlsx", options);
Tell the exporter you want to have data aware export and handle CustomizeCell event to set cell wrapping to true:
XlsxExportOptionsEx options = new XlsxExportOptionsEx()
{
ExportType = DevExpress.Export.ExportType.DataAware
};
options.CustomizeCell += options_CustomizeCell;
void options_CustomizeCell(DevExpress.Export.CustomizeCellEventArgs e)
{
e.Formatting.Alignment = new XlCellAlignment() { WrapText = true };
e.Handled = true;
}
Then use the customized options object for export.
See: https://www.devexpress.com/Support/Center/Question/Details/T381176
There is also the RenderBrick event which sometimes may be helpful. You may handle it like:
gveExporter.RenderBrick += gveExporter_RenderBrick;
void gveExporter_RenderBrick(object sender, DevExpress.Web.ASPxGridViewExportRenderingEventArgs e)
{
...
StringFormat sFormat = new StringFormat(StringFormatFlags.NoWrap);
BrickStringFormat brickSFormat = new BrickStringFormat(sFormat);
e.BrickStyle.StringFormat = brickSFormat;
...
}
But I have not found how to actually force cell wrap there, because StringFormatFlags has only NoWrap among suitable items. In my experience I did have cell wrapping long text in the exported Excel doc, so I've used RenderBrick to switch that wrapping off.
Hope that helps.

Fetching content of multiline textbox using Visual Studio

TextBox txtContent = new TextBox();
SPList announcementList = mySite.Lists["Announcements"];
SPListItem getAnnouncement = announcementList.Items[0];
txtContent.Text = getAnnouncement["Body"].ToString();
this gives output as
<div class="ExternalClass61EB4AB2F639401D9141EADFC30FEDFE">
<p>Please follow plan of action.​</p>
</div>
I want output as
"Please follow plan of action."
Please Guide.
Use SPFieldMultiLineText like the following:
SPListItem getAnnouncement = announcementList.Items[0];
SPFieldMultiLineText bodyField = getAnnouncement.Fields.GetField("Body") as SPFieldMultiLineText;
string txt = bodyField.GetFieldValueAsText(getAnnouncement["Body"]);
string html = bodyField.GetFieldValueAsHtml(getAnnouncement["Body"]);
If you're looking to remove the HTML from the content, this answer will help you:
How can I strip HTML tags from a string in ASP.NET?
There are a number of solutions there, such as the one with Regex. You would just need this line of code:
txtContent.Text=WebUtility.HtmlDecode(Regex.Replace(getAnnouncement["Body"].ToString(), "<[^>]*(>|$)", string.Empty))
SPHttpUtility.ConvertSimpleHtmlToText(text, text.Length - 1);

Depending source for drop down list

I have one drop down list in my pages that its source comes of below code. Now I like to put 1 text box adjusted on my drop down list and when I type on that, source of drop down list (DocumentNo) depend on what I type in the text box and when text box is null drop downs list shows all the (DocumentNo) , please help how I have to change my code,
protected void ddlProjectDocument_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
var query = from p in _DataContext.tblDocuments
orderby p.DocumentNo
select p;
int maxs = 0;
foreach (tblDocument v in query)
{
if (v.DocumentNo.Length > maxs)
maxs = v.DocumentNo.Length;
}
foreach (tblDocument vv in query)
{
string doctitle = vv.DocumentNo;
for (int i = vv.DocumentNo.Length; i < maxs; i++)
{
doctitle += " ";
}
doctitle += " | ";
doctitle += vv.TITLE;
// Use HtmlDecode to correctly show the spaces
doctitle = HttpUtility.HtmlDecode(doctitle);
ddlProjectDocument.Items.Add(new ListItem(doctitle, vv.DocId.ToString()));
}
}
First, I would highly recommend storing the result of that query at the beginning of the method into something like a session variable so that you don't have to continually query the database every time you hit this page.
Second, you should use the OnTextChanged event in ASP.NET to solve this problem. Put in the OnTextChanged attribute to point to a method in your code behind that will grab the query result values (now found in your session variable) and will reset what is contained in ddlProjectDocument.Items to anything that matched what was being written by using String.StartsWith():
var newListOfThings = queryResults.Where(q => q.DocumentNo.StartsWith(MyTextBox.Value));
At this point all you need to do is do that same loop that you did at the end of the method above to introduce the correct formatting.

How to show pop up menu from database in gridview on each gridview row items?

How to show pop up menu from database in gridview on each gridview row items ?
Example of this is :
http://www.redbus.in/Booking/SelectBus.aspx?fromCityId=733&fromCityName=Delhi&toCityId=757&toCityName=Manali&doj=26-Dec-2010&busType=Any
Move your cursor to Departure time and arrival time...a want this type of popup in gridview items....which fetch entries from database..
You can handle this with javascript/jQuery. The gridview itself has nothing to do with this.
If I was going to build what he has just by looking at it I would create the table dynamically. This way you could use a string builder and insert variable names in between each td tag. You retrieve all your data from the database and store in a List or even better use LINQ to SQL.
I wish I could give you a sample in VB, but here is an example of what I'm talking about.
protected void Page_Load(object sender, EventArgs e)
{
StoreDataContext db = new StoreDataContext();
var join = from b in db.Brands
select new
{
Brand = b,
c = b.Description.Length < 204 ? b.Description : b.Description.Substring(0, 204) + "...",
Sources =
from s in db.Sources
join xref in db.Brands_Sources on s.SourceID equals xref.SourceID
where xref.BrandID == b.BrandID
select s
};
StringBuilder sb = new StringBuilder();
sb.Append( "<table class='tableStripe'>");
sb.Append( "<tr><th width='1%'>Active</th><th>Image</th><th>Name</th><th>Short Description</th><th>Source</th><th width='1%'>Date Created</th><th width='1%'>Data Modified</th></tr>");
foreach (var result in join)
{
string chk = (result.Brand.Active ? "checked='checked'" : "");
sb.AppendFormat( "<tr><td><input class='brandChk' value='{4}' type='checkbox' {0}></td><td width='1%'><img width='50px' src='{1}'</img></td>" +
"<td><a href='/admin/Catalog/Brand/Detail.aspx?brandId={4}'>{2}</a></td><td width='60%'>{3}</td>", chk, result.Brand.Image, result.Brand.Name, result.c,result.Brand.BrandID);
sb.Append("<td>");
foreach (var q in result.Sources)
{
string srcname = (q.Source1=="Motovicity" ? "Motovicity":"Direct");
sb.AppendFormat("<img src='{0}' title='{1}'</img>", q.Image,srcname);
}
string date = string.Format("{0:MM/dd/yy}", result.Brand.DateCreated);
string mod = string.Format("{0:MM/dd/yy}", result.Brand.DateModified);
sb.Append("</td>");
sb.AppendFormat("<td>{0}</td><td>{1}</td></tr>", date, mod);
}
sb.Append("</table>");
resultSpan.InnerHtml = sb.ToString();
}
As you can see I code the html for a checkbox and insert the brand id into the value attribute.
He is not fetching record on runtime basically if you see the structure he has the information in the tooltip attribute of anchor tag and using jquery cluetip to display it.
so you can use any jquery tooltip plugin to display same as he is doing.
Thanks

Resources