Archive

Author Archive

Data Relation using Data Set in .Net

DataSet:

The DataSet class represents a memory-resident database. It is a container for the DataTable and DataRelation classes.DataRelationIt is a Class to establish relation with more than one data in the dataset.

DataRelation class constructor takes three arguments to establish relationship with other table.
1. Strdatarelationname(String type).
2. Parent table columan name.
3. Child table columan name.

To get all data againsed parent table column name you have to use GetChildRows method, which takes one
arguments( Strdatarelationname). and after getting all fields value of child table you can go further with your own code whatever you want.

Here below code gives you example to relate two table using particular field of table.

DataSet ds = null;
protected void Page_Load(object sender, EventArgs e)
{
ds = new DataSet();
ds.Tables.Add(MakeAuthorData());
ds.Tables.Add(MakeBookData());

DataRelation relation = new DataRelation(“Book2Author”, ds.Tables[“Authors”].Columns[“AuthorId”], ds.Tables[“Books”].Columns[“AuthorId”]);
ds.Relations.Add(relation);

grdAuthors.DataSource = ds.Tables[“Authors”].DefaultView;
grdAuthors.DataBind();

grdBooks.DataSource = ds.Tables[“Books”].DefaultView;
grdBooks.DataBind();

foreach (DataRow artistRow in ds.Tables[“Authors”].Rows)
{
string fname = (string)artistRow[“FirstName”];
string lname = (string)artistRow[“LastName”];
labReport.Text += “” + fname + ” ” + lname;
foreach (DataRow bookRow in artistRow.GetChildRows(relation)) //Get child table fields
{
string title = (string)bookRow[“Title”];
labReport.Text += “” + title;

}
}
}
private DataTable MakeAuthorData()
{
DataTable table = new DataTable();
table.TableName = “Authors”;

DataColumn idCol = new DataColumn();
idCol.ColumnName = “AuthorId”;
idCol.DataType = typeof(Int32);
idCol.AllowDBNull = false; idCol.Unique = true;

DataColumn firstNameCol = new DataColumn(“FirstName”, typeof(string));
DataColumn lastNameCol = new DataColumn(“LastName”, typeof(string));

table.Columns.Add(idCol);
table.Columns.Add(firstNameCol);
table.Columns.Add(lastNameCol);

DataRow r1 = table.NewRow();
r1[0] = 10;
r1[1] = “A”;
r1[2] = “a”;
table.Rows.Add(r1);

DataRow r2 = table.NewRow();
r2[0] = 20;
r2[“FirstName”] = “B”;
r2[“LastName”] = “b”;
table.Rows.Add(r2);

DataRow r3 = table.NewRow();
r3[0] = 30; r3[“FirstName”] = “C”;
r3[“LastName”] = “c”;
table.Rows.Add(r3);

DataRow r4 = table.NewRow();
r4[0] = 40; r4[“FirstName”] = “D”;
r4[“LastName”] = “d”;
table.Rows.Add(r4);
return table;
}

private DataTable MakeBookData()
{
DataTable table = new DataTable();
table.TableName = “Books”;

DataColumn idCol = new DataColumn();
idCol.ColumnName = “Id”;
idCol.DataType = typeof(Int32);
idCol.AllowDBNull = false;
idCol.Unique = true;
idCol.AutoIncrement = true;

DataColumn authorCol = new DataColumn(“AuthorId”, typeof(Int32));
DataColumn nameCol = new DataColumn(“Title”, typeof(string));
DataColumn priceCol = new DataColumn(“Price”, typeof(double));

table.Columns.Add(idCol);
table.Columns.Add(authorCol);
table.Columns.Add(nameCol);
table.Columns.Add(priceCol);
DataRow r1 = table.NewRow();
r1[1] = 30;
r1[2] = “Java”;
r1[3] = 49.99;
table.Rows.Add(r1);

DataRow r2 = table.NewRow();
r2[1] = 10;
r2[2] = “C#”;
r2[3] = 19.99;
table.Rows.Add(r2);

DataRow r3 = table.NewRow();
r3[1] = 40; r3[2] = “Javascript”;
r3[3] = 24.99;
table.Rows.Add(r3);

DataRow r4 = table.NewRow();
r4[1] = 40; r4[2] = “Oracle”;
r4[3] = 24.99;
table.Rows.Add(r4);
return table;
}
}

Happy Coding.

Categories: .Net Tags:

How to programmatically change the password of currently logged in user in Dot Net Nuke?

If you want to change password of currently logged in user. Then following code can be helpful for you.

Boolean changepass = UserController.ChangePassword(this.UserInfo,
YourOldPassword.Text, YourNewPassowrd.Text);

if (changepass)
{
DotNetNuke.UI.Skins.Skin.AddModuleMessage
(this, “Your Password has been changed successfully”,
DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.GreenSuccess);

}

Thanks

Categories: DotNetNuke Tags:

Some Important DotNetNuke Skin Tokens!!

DotNetNuke is a great ASP .Net based CMS with is widely used across the system. It supports many exciting features which makes management, extension of website really easy, Allowing you to concentrate on your business need. DNN  is structured in a modular way, depending upon your need you can choose between modules to be included in your website. The same modular approach has been used to Skin DNN. Skinning defines how a DNN will appear.

Following are some very useful token which can be used while creating a DNN skin.

Name Token Description
Logo [LOGO] This holds a graphics file which represents the
entity or the topic your site is about. This is
commonly referred to a banner, but don’t confuse
this with the DNN banner skin object listed next.
Banner [BANNER] This is a place holder for advertising banners.
Menu [NAV] This is the menu or navigational control of the site.
In the past, the tokens [SOLPARTMENU] and
[MENU] have been used.
Search [SEARCH] This allows users to search the content within your
site, or now, with later versions of DNN, the web.
Language [LANGUAGE] On a multilingual DNN site, it allows the user to
change his/her preferred language.
Current Date [CURRENTDATE] This simply displays the current date based on the
location of the web server.
Breadcrumb [BREADCRUMB] Lists out the hierarchical location of the page you’re
currently on.
Username [USER] This will display your username when you’re
logged in or Register when you’re not. When it
displays your username, it will link the user to their
account settings. When it displays Register, it will
link to a page where the user may register.
Login [LOGIN] Allows users to log in and log out.
Copyright [COPYRIGHT] Displays a simple copyright notice.
Name Token Description
Terms of Use [TERMS] Links to a page where the terms of use are located.
Privacy
Statement
[PRIVACY] Links to a page where the privacy statement is
mentioned.
DotNetNuke
Copyright
[DOTNETNUKE] Displays copyright information on DotNetNuke
and links to its site.
Help [HELP] Displays the text Help as a link to the site’s
administrator.
Host Name [HOSTNAME] Displays a link to the host portal within the DNN
install.
Tree View
Menu
[TREEVIEWMENU] Serves as a navigational menu with expandable and
collapsible nodes. This is typically used on the left
side of a DNN skin.
Links [LINKS] Displays a list of links to the parent and sibling
levels of pages within the site. This makes it easier
for search engines to index your site.

Hope this helps!!

Categories: DotNetNuke Tags:

How to call a web service using jquery?

June 4, 2011 1 comment

JQury is a really powerful library which can be used to do many task. Its moto is do more write less to do more.
In this post I will explain you how to call a Webservice using JQuery.

You can call a webservice function from jQuery too, but it’s a lot more harder and lot less fun. Here’s how you can do that.

1. Decorate your web-service / pagemethod with the [WebMethod] attribute so that they serialize to JSON (jQuery does not support WSDL).
2. Make only POST requests.
3. Send an empty JSON variable to the web service if you don’t have any arguments.

The $.ajax function of jQuery can be used to make the request at the client end. Here’s a sample

$.ajax({ url: “/webservice.asmx/DoSomething”,
type: “post”,
data: “{}”,
contentType: “applicatin/json; charset=utf-8”,
dataType: “json”,
success: function(result) {
alert(msg.d);
},
error: function(err) {
alert(“error!”);
}
});

Notice that in the success callback function we the reference is to msg.d and not to the msg itself. This is because ASP.Net wraps the JSON serialized data in a variable called ‘d’. It’s a convention to improve data security.

Categories: JQuery Tags:

Interesting difference between CSS Padding and Margin tags and innerText and innerHTML function

Have you ever wondered the difference between CSS Padding and Margin tage?

Padding defines the spacing between your element and the boarder, while the margin defines the spacing between your border and any other outer elements in your CSS layout.

Here is an example that should help further clarify:

1) Border = 0, padding = 0, margin = 0

Sample Text

2) Border = 10px, padding = 0, margin = 0

Sample Text

3) Border = 10px, padding = 10px, margin = 0

Sample Text

As you can see the margin defines the space outside your border and between other elements, while the padding defines the space between your element and the elements border. Hopefully by understanding the difference you can more effectively utilize your CSS margin and CSS padding properties.

It will be worth to add another commonly miss understood difference between innerHTML and innerText.

innerHTML returns all of the markup and content within a given element.

innerText returns all of text content within a given element.

Hi There

InnerHTML of H1 would be: Hi There

InnerText of H1 would be: Hi There

Hope this bit code is helpful for you.

Happy styling 🙂

Categories: CSS Tags:

Types of stylesheet and it’s priority level

There are three types of CSS styles:

  • inline styles
    Inline styles are styles that are written directly in the tag on the document. Inline styles affect only the tag they are applied to.

    <a href="" style="text-decoration: none;">
  • embedded styles
    Embedded styles are styles that are embedded in the head of the document. Embedded styles affect only the tags on the page they are embedded in.

    <style type="text/css"> p { color: #00f; } </style>
  • external styles
             External styles are styles that are written in a separate document and then attached to various Web documents.
             External style sheets can affect any document they are attached to.
<link rel="stylesheet" type="text/css" href="styles.css" />

CSS best practices recommends that you use primarily external style sheets for styling Web pages so that you get the most benefit.

It’s priority level is followings.

Inline styles  has high priority then embedded styles and external styles has the lowest priority.

Happy styling. 😉

Categories: CSS Tags: ,

Access HTML Element using Javascript/JQuery

Java Script

There are two ways to access html element from javascript.

Let us suppose your HTML file has the following content.

<html>

<head>

</head>

<body>

<form >

<input type=”text” id=”txtusername” name=”txtusername” />

<input type=”password” id=”txtpassword” name=”txtpassword” />

<input type=”submit” value=”Submit” />

</form>

</body>

</html>

Then you can access any element using the code lines below

1.          var username=document.getElementById(“txtusername”).value;

2.          var username=  document.forms[0].txtusername.value;

I hope this was helpful to you.

 

JQuery

The code snippet below shows how to access html element from jquery.

Let us suppose your HTML file has following content.

<html>

<head>

/* add jquery library reference in your code.

If you haven’t yet downloaded it then you can download from http://docs.jquery.com/

*/

<script type=”text/javascript” src=”jquery1.4.2.js” />

</head>

<body>

<form >

<input type=”text” id=”txtusername” name=”txtusername” />

<input type=”password” id=”txtpassword” name=”txtpassword” />

<input type=”submit” value=”Submit” />

</form>

</body>

</html>

You can access any element using the below lines:

$(document).ready(function() // function called when page load is complete

{

$username=$(‘#txtusername’).val();

alert(“Hello ! Mr.  “+$username);

});

Hope this small bit of code was helpful to you.

Categories: JavaScript, JQuery Tags: ,
%d bloggers like this: