Home > ASP.NET > Manipulating datas From gridview

Manipulating datas From gridview


asp:GridView ID="grdSaleList" runat="server" AutoGenerateColumns="false" EmptyDataText="No Files Found"
DataKeyNames="ListFileId,ListFileName" CellPadding="3" CssClass="grid"
onrowcommand="grdSaleList_RowCommand" onrowdatabound="grdSaleList_RowDataBound"

And the screen shot of gridview is

gridview structre

gridview structre


If(!ispostBack)
{
loadGrid(); //write code to fill grid
}

protected void grdSaleList_RowDataBound(object sender, GridViewRowEventArgs e)
{

try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
ImageButton imgdel = e.Row.FindControl("lnkDelete") as ImageButton;
imgdel.Attributes.Add("onclick", "javascript:return confirm('Are you want To Delete This File'"+DataBinder.Eval(e.Row.DataItem,"Title")+" ?')");

}
}
catch (Exception ex)
{
divErrorMessage.InnerHtml = ex.Message;
}

}

protected void grdSaleList_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
string id = e.CommandArgument.ToString();
GridViewRow currentRow = (GridViewRow)((Control)e.CommandSource).NamingContainer;
string fileName = Convert.ToString(grdSaleList.DataKeys[currentRow.RowIndex].Values[1]);
//gets the second keyvalue .In this case first key value is Id
if (e.CommandName == "ViewFile")
{
downloadFile(fileName);
}
if(e.CommandName=="DeleteFile")
{
DeleteListFile(id, fileName);
}
}
catch (Exception ex)
{
divErrorMessage.InnerHtml = ex.Message;
}
finally
{

}
}

Advertisements
Categories: ASP.NET
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: