web stats analysis

Archive for September 3rd, 2013

How to get selected row values in gridview asp.net?

The sample code is below try it:

Use the below code html page.


<asp:GridView runat="server" ID="grdprj"AutoGenerateColumns="false"

OnRowCommand="grdprj_RowCommand">

<Columns>

<asp:BoundField HeaderText="Projcet Name" DataField="ProjectName" />

<asp:ButtonField ButtonType="Link" CommandName="Select" Text="Select" />

</Columns>

</asp:GridView>

Use the below code in code behind page:


protected void grdprj_RowCommand(object sender, GridViewCommandEventArgs e)

{

// If multiple buttons are used in a GridView control, use the

// CommandName property to determine which button was clicked.

if (e.CommandName == "Select")

{

// Convert the row index stored in the CommandArgument

// property to an Integer.

int index_page = Convert.ToInt32(e.CommandArgument);

// Retrieve the row that contains the button clicked

// by the user from the Rows collection.

GridViewRow grdrow = grdprj.Rows[index_page];

}

}

How to make download link in asp.net?

I store images in database as byte array.And I want to open the image in a page after clicking
button.I have tried response.binarywrite() method keeping the page content type=”image” but can not save that in jpg or jpeg format.so how to do in c#?

You use below code:


string FileName ="image1.jpg";
byte[] bytes =  // get from the database table using your DB code/function
Response.Clear();
Response.AppendHeader("Content-Disposition", "filename=" + FileName);
Response.AppendHeader("Content-Length", bytes.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(bytes);
Response.End();

How to read data from excel file using c#?

using OleDB and use the Excel file like a datatable in a database you can read data from excel file.

Like see in below example:


string con = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=path;
Extended Properties='Excel8.0;HDR=Yes;'"
using(OleDbConnection cn= new OleDbConnection(con))
{
cn.Open();
OleDbCommand olcmd = new OleDbCommand("select * from [Sheet1$]", cn)
using(OleDbDataReader dr = olcmd.ExecuteReader())
{
while(dr.Read())
{
var row1Col0 = dr[0];
Console.WriteLine(row1Col0);
}
}
}

Above example use the Microsoft.Jet.OleDb.4.0 provider to open and read the Excel file.

Does not contain a definition and no extension method accepting a first argument of type could be found (are you missing a using directive or an assembly reference?)

Solution of does not contain a definition and no extension method accepting a first argument of type could be found (are you missing a using directive or an assembly reference?).

Just add the below namespace:

System.Xml.Linq.XElement;