public static List<List<T>> Split<T>(List<T> source) { return source .Select((x, i) => new { Index = i, Value = x }) .GroupBy(x => x.Index / 4) .Select(x => x.Select(v => v.Value).ToList()) .ToList(); }
Hi All In this blog you will get to know some of the problems i have faced during my day to day work. and the solutiosn that i have used for those problems.
Monday, March 18, 2013
c# split list into sub lists
Read file content with File reader
using (StreamReader stream = File.OpenText(PathOfFile)) { string fileContentsDatas = stream.ReadToEnd();
}
Friday, February 1, 2013
Fluient nhibernet syntaxes
After a long time working on nhibernet fluient
I like that much with c# syntax
It is really good rather than the normal syntax with xmles
I like that much with c# syntax
It is really good rather than the normal syntax with xmles
Handlin radio button with value javascript
<script type="text/javascript">
function Str() {
var theSelectedRadio = document.getElementsByName("x");
for (var i = 0; i < theSelectedRadio.length; i++) {
if (theSelectedRadio[i].checked) {
alert(theSelectedRadio[i].value);
}
}
}
</script>
<body>
</body>
<input id="x" type="radio" name="x" value="true" />
<input id="y" type="radio" name="x" value="false" />
<input id="z" type="radio" name="x" value="NotSelected" />
<input type="radio" name="x" value="NotSelectedThere" />
<input type="button" value="s" onclick="Str()" />
function Str() {
var theSelectedRadio = document.getElementsByName("x");
for (var i = 0; i < theSelectedRadio.length; i++) {
if (theSelectedRadio[i].checked) {
alert(theSelectedRadio[i].value);
}
}
}
</script>
<body>
</body>
<input id="x" type="radio" name="x" value="true" />
<input id="y" type="radio" name="x" value="false" />
<input id="z" type="radio" name="x" value="NotSelected" />
<input type="radio" name="x" value="NotSelectedThere" />
<input type="button" value="s" onclick="Str()" />
Sunday, November 18, 2012
Adding namespace in xml serialization
new XmlSerializerNamespaces().Add("p", http://xxx);
Saturday, October 20, 2012
Wednesday, October 17, 2012
Getting deserialized object from the xml string
public static T DeserializeFromXml<T>(string xml) { T result; XmlSerializer ser = new XmlSerializer(typeof (T)); using (TextReader tr = new StringReader(xml)) { result = (T) ser.Deserialize(tr); } return result; }
Getting xml serialization in string c#, a usefule method, a generic method
public static string ToXml(object Obj) { XmlSerializer ser = new XmlSerializer(Obj.GetType()); string xml; using (MemoryStream memStream = new MemoryStream()) { XmlTextWriter xmlWriter = new XmlTextWriter(memStream, Encoding.UTF8); xmlWriter.Formatting = Formatting.Indented; xmlWriter.Indentation = 1; xmlWriter.IndentChar = Convert.ToChar(9); ser.Serialize(xmlWriter, Obj); xmlWriter.Close(); memStream.Close(); xml = Encoding.UTF8.GetString(memStream.GetBuffer()); xml = xml.Substring(xml.IndexOf(Convert.ToChar(60))); xml = xml.Substring(0, (xml.LastIndexOf(Convert.ToChar(62)) + 1)); } return xml; }
Sending xml data to other asp.net page in Request Inputsstream object
http://dotnetslackers.com/Community/blogs/haissam/archive/2007/11/26/ways-to-pass-data-between-webforms.aspx
1- Query String
2- Cookies
3- Session variables
4- Cross Page Posting
5- Submit form
6- Server.Transfer or Server.Execute
We will talk in details about each one and which kind of data it could store.
1- Querystrings: Using Query string variables, you can pass data between webforms. below is an example
Ex: Suppose you want to pass the TextBox1.Text variable from WebForm1 to WebForm2 on button click event.
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("WebForm2.aspx?id=" + TextBox1.Text);
}
To Read the value of "id" in WebForm2, you should use the below code
string queryStringID = Request.QueryString["id"];
Now queryStringID will hold the data from the querystring.
2- Cookies: AS you might already know, cookies are small text files stored in the client machine. Cookies can only store up to approximately 4 kbs.
Once the cookie is stored into the client machine, each request from the client to your application, the web browser will look for the cookie and send it via the Request Object.
Ex: To store a value of TextBox1.Text inside the cookie use the below code
protected void Button1_Click(object sender, EventArgs e)
{
HttpCookie cookie = new HttpCookie("UserName");
cookie.Value = TextBox1.Text;
cookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(cookie);
Response.Redirect("WebForm2.aspx");
}
Now in webform2 page_load event, you should write the below code to get the value
if(Request.Cookies["UserName"] != null)
Response.Write(Request.Cookies["UserName"].Value);
3- Session Variables: By default, session variables are stored in the webserver's memory. Session variables are unique per each user.
Ex: To store a value inside a session variable use the below code
protected void Button1_Click(object sender, EventArgs e)
{
Session["UserName"] = TextBox1.Text;
Response.Redirect("WebForm2.aspx");
}
To retrieve the value from WebForm2 use the below code
Response.Write(Session["UserName"]);
1- Query String
2- Cookies
3- Session variables
4- Cross Page Posting
5- Submit form
6- Server.Transfer or Server.Execute
We will talk in details about each one and which kind of data it could store.
1- Querystrings: Using Query string variables, you can pass data between webforms. below is an example
Ex: Suppose you want to pass the TextBox1.Text variable from WebForm1 to WebForm2 on button click event.
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("WebForm2.aspx?id=" + TextBox1.Text);
}
To Read the value of "id" in WebForm2, you should use the below code
string queryStringID = Request.QueryString["id"];
Now queryStringID will hold the data from the querystring.
2- Cookies: AS you might already know, cookies are small text files stored in the client machine. Cookies can only store up to approximately 4 kbs.
Once the cookie is stored into the client machine, each request from the client to your application, the web browser will look for the cookie and send it via the Request Object.
Ex: To store a value of TextBox1.Text inside the cookie use the below code
protected void Button1_Click(object sender, EventArgs e)
{
HttpCookie cookie = new HttpCookie("UserName");
cookie.Value = TextBox1.Text;
cookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(cookie);
Response.Redirect("WebForm2.aspx");
}
Now in webform2 page_load event, you should write the below code to get the value
if(Request.Cookies["UserName"] != null)
Response.Write(Request.Cookies["UserName"].Value);
3- Session Variables: By default, session variables are stored in the webserver's memory. Session variables are unique per each user.
Ex: To store a value inside a session variable use the below code
protected void Button1_Click(object sender, EventArgs e)
{
Session["UserName"] = TextBox1.Text;
Response.Redirect("WebForm2.aspx");
}
To retrieve the value from WebForm2 use the below code
Response.Write(Session["UserName"]);
Wednesday, December 14, 2011
Replace in sql
REPLACE ( string_expression , string_pattern , string_replacement )
Monday, December 5, 2011
Charindex in sql
SET @FullName = 'www.java2s.com'
SET @SpaceIndex = CHARINDEX('java', @FullName)
SELECT LEFT(@FullName, @SpaceIndex - 1)
SET @SpaceIndex = CHARINDEX('java', @FullName)
SELECT LEFT(@FullName, @SpaceIndex - 1)
Friday, December 2, 2011
Radio button with gridview asp.net
Hi Ther,
We are facing many problems with including radio button with grid
one of them is all are selected because they are generating different name in html
to overcome we have to do the following then its easy.
in html code we have to assign its checked chang event and in code back we have to write the code like this
foreach (GridViewRow row in gridViewProducts.Rows)
{
((RadioButton)row.FindControl("radioButtonToSelectTheProductResult")).Checked = false;
}
var radioButton = (RadioButton)sender;
radioButton.Checked = true;
then what we are doing here is setting first all check box to false and then the one who is sender to true.
by default with radio we are giving customer to select one, we are not allowing to deselect all.
so one who is clicked is already selected in grid.
It is working correctly there.
Engjoy radiobutton with gridview
Thanks & Regards
Nipam Budhabhatti
We are facing many problems with including radio button with grid
one of them is all are selected because they are generating different name in html
to overcome we have to do the following then its easy.
in html code we have to assign its checked chang event and in code back we have to write the code like this
foreach (GridViewRow row in gridViewProducts.Rows)
{
((RadioButton)row.FindControl("radioButtonToSelectTheProductResult")).Checked = false;
}
var radioButton = (RadioButton)sender;
radioButton.Checked = true;
then what we are doing here is setting first all check box to false and then the one who is sender to true.
by default with radio we are giving customer to select one, we are not allowing to deselect all.
so one who is clicked is already selected in grid.
It is working correctly there.
Engjoy radiobutton with gridview
Thanks & Regards
Nipam Budhabhatti
Friday, November 18, 2011
Modal popup-;extender control with asp. net
Normal ajax popup extender control is using the client side calls.
so from backside if we want to starts the modal control from code
then first we have to give the faxe control for target control id
then from code we can show extender.Show(); method
then we can choosse the update panel to open it also at the time of update panel.
Thanks & Regards
Nipam Budhabhatti
so from backside if we want to starts the modal control from code
then first we have to give the faxe control for target control id
then from code we can show extender.Show(); method
then we can choosse the update panel to open it also at the time of update panel.
Thanks & Regards
Nipam Budhabhatti
Friday, August 5, 2011
Javascript with Scriptmanager
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "xxx", "alert('Hello World!');", true);
Wednesday, August 3, 2011
Change the schema in sql server 2008
alter
schema portal transfer dbo.table1
It has been long time
It has been a long time since i am active too
Subscribe to:
Posts (Atom)