Sorting Gridview Using Jquery Table Sorter plugin.

Sorting is very much needed while working with Gridview. We can sort data using code in code behind file and also using Jquery.

In this article I will use jquery  TableSorter plugin to sort data in gridview. It is very easy to implement.

Create a table:





Click on Image to Enlarge View



Now add a simple webform in your application. Add following jquery CDN and Jquery code to head section of HTML markup.

Show File icons with filename in Asp.Net.

In asp.net we can show file Icons according to file extension. It looks attractive if we show Icons with file name in gridview or othe places. In this article I will explain how to show icon with file name according to its extension.
This concept is based on extension of the file. We will check the extension of the file and show the icon accordingly.

Execute or Run JavaScript code from code behind in Asp.Net.

Execute or Run JavaScript code from code behind in Asp.Net.

While working in Asp.Net, we need to execute JavaScript code from code behind. In this article I will explain how to execute JavaScript code in Code behind.

Function to Run/ Execute JavaScript code in Code behind in Asp.Net: 


public void RunJavaScriptCode(System.Web.UI.Page page, string strCode)
    {
        string strJavaScriptCode = "<script language=\"javascript\" type=\"text/javascript\">";
        strJavaScriptCode += strCode;
        strJavaScriptCode += "</script>";

        if (!page.ClientScript.IsClientScriptBlockRegistered("alert"))
            ClientScript.RegisterClientScriptBlock(GetType(), "alert", strJavaScriptCode);
    }

Show Message and redirect to other page in asp.net

In this article I will explain how to show pop up message and redirect on clicking “ok” button of message.


click on Image to Enlarge View

Function to Show message and Redirect to other page:
How to download any type of file from FTP server in ASP.NET (C#)?

How to download any type of file from FTP server in ASP.NET (C#)?

Introduction:

We can download all type of file like  CSV, Docx, PNG, JPG, PDF etc from FTP server in asp.net using c#. I have share the code in this article.. We can download any type of file from server using this code. Just change the Extension of the file or mention multiple files extension.



Code to Download All type of Files(CSV, Docx, PNG, JPG, PDF) from FTP Server:

Open or View all type of files (Like Images, Docx, Pdf etc) in ASP.NET(C#)

In this article I will explain How to open or view files in Gridview. While working with Gridview we face a situation where we want to show filename in Gridview  and want to open them on click. Like given in Attached Image.
Open/View Files in Gridview(Click Image to Enlarge view)

Dynamic control inside Repeater using placeholder in Asp.Net(c#)?

In this article I will explain how to create dynamic control inside repeater using placeholder. Using placeholder we can add dynamic control from code behind like TextBox, RadioButtonList, Checkbox etc (depending upon the condition).
In this Example, I am creating small Question paper with different options to give your answer, Like Textbox to enter your answer, Radio button list to select answer and checkboxlist to select multiple answers.
Click on image to enlarge view

Follow these steps:
      1. Create a simple web form in your application.
      2. Now add a Repeater control to this web form.
      3. Customize repeater control as per your requirement and add a Placeholder control where you want     to insert Input control.
      4. No add ItemDataBound event handler.
      5. Bind Repeater and write code on ItemDataBound event handler to generate Dynamic control.

Create a Table in database:


Design or Html Part of Demo Application:

<asp:Repeater ID="rptPrint" runat="server" OnItemDataBound="rptPrint_ItemDataBound">
<ItemTemplate>
  <table style="width: 7.6in">
     <tr>
<td colspan="5" style="width: 7in">
 <strong>
  <asp:Label ID="LblQuestion" Text='<%#Eval("Question")%>'         runat="server"></asp:Label></strong><br />
<asp:HiddenField ID="hfAnswer" Value='<%#Eval("Answer") %>' runat="server" />
<asp:HiddenField ID="hfType" Value='<%#Eval("Type") %>' runat="server" />
 </td>

     </tr>
     <tr>
<td colspan="4">
<asp:PlaceHolder ID="phRow" runat="server" />
 <br />
 </td>
     </tr>
   </table>
</ItemTemplate>

<FooterTemplate>
</FooterTemplate>
</asp:Repeater>


Now write the following code in Code behind:

Add Following Namespace:

using System.Data.SqlClient;
using System.Data;
using System.Configuration;

Now Bind Repeater on Page Load and Generate Dynamic control on ItemDataBound:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
Fill_Repeater();
}

private void Fill_Repeater()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString());
if (con.State == ConnectionState.Open)
con.Close();

con.Open();
SqlDataAdapter adp = new SqlDataAdapter("Select * from Question", con);
DataTable dt = new DataTable();
adp.Fill(dt);

if (dt.Rows.Count > 0)
{
rptPrint.DataSource = dt;
rptPrint.DataBind();
}
}

protected void rptPrint_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
string options = ((HiddenField)e.Item.FindControl("hfAnswer")).Value;
string type = ((HiddenField)e.Item.FindControl("hfType")).Value;
Label lblquestion = ((Label)e.Item.FindControl("LblQuestion"));

PlaceHolder phRow = (PlaceHolder)e.Item.FindControl("phRow");

if (type == "Text")
{
TextBox txtAnswer = new TextBox();
phRow.Controls.Add(txtAnswer);
}

//Check Box Options for Questions

else if (type == "Check")
{
CheckBoxList chklist = new CheckBoxList();
chklist.RepeatDirection = RepeatDirection.Horizontal;
chklist.Font.Italic = true;

chklist.RepeatColumns = 4;

foreach (string option in options.Split(','))
{

ListItem items = new ListItem();
items.Text = option;
items.Value = option;
chklist.Items.Add(items);
}
phRow.Controls.Add(chklist);
}


//Radio options for Question

else
{
RadioButtonList rdblist = new RadioButtonList();
rdblist.RepeatDirection = RepeatDirection.Horizontal;
rdblist.Font.Italic = true;

rdblist.RepeatColumns = 4;

foreach (string option in options.Split(','))
{

ListItem items = new ListItem();
items.Text = option;
items.Value = option;
rdblist.Items.Add(items);
}

phRow.Controls.Add(rdblist);
}

}

}

Note: In case you have any doubt in above post , you can leave your query in comment section or Email me on programmerskill@gmail.com.


Kategori

Kategori