Introduction | |
|
Monthly Archives: November 2010
Asp.Net GridView Control Custom Sorting and Paging with C#
pass parameters to popup window with showModalDialog +aspx
Write this code at Header
function Popup() {
var x = document.getElementById(‘<%=txtRegIDS.ClientID %>’).innerText;
//For showModalDialog Popup Window
window.showModalDialog(“view-student-edu-doc.aspx?param1=” + x, null, ‘status:no;dialogWidth:770px;dialogHeight:500px;dialogHide:true;help:no;scroll:no’)
//For Simple Popup Window
// window.open(“view-student-edu-doc.aspx?param1=” + x, ‘window’, ‘width=780,height=620,menubar=no, resizable=no,scrollbars=no,left=280,top=250’)
}
//Html Code
<asp:Button id=”Button1″ Text=”Student Document” OnClientClick=”Popup()” runat=”server” />
<div style=”visibility:hidden”> <asp:Label ID=”txtRegIDS” runat=”server” ></asp:Label></div>
//Get this Parm value to another Page with querystring and load the specific information
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
if (Request.QueryString[“param1”] != null && Request.QueryString[“param1”] != string.Empty)
{
int ID = Convert.ToInt32(Request.QueryString[“param1”].ToString());
gvStdDocument(ID);
}
}
}
public void gvStdDocument(int RegID)
{
DataSet ds = DALCourseRequirdDocument.GetStudentEduDoc(RegID);
////ViewStudenttDocumentRequestsStatus
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
gv.DataSource = ds;
gv.DataBind();
// //gvDocmentdetail
}
}
//The gridview data of Popup window
<div>
<asp:GridView ID=”gv” runat=”server” AutoGenerateColumns=”False” Width=”100%” DataKeyNames=”CRD_ID,doc_uploadID”
PageSize=”50″ EmptyDataText=”No record found” CellPadding=”4″ GridLines=”None”>
<HeaderStyle CssClass=”grid_head” />
<RowStyle CssClass=”data_set1″ />
<AlternatingRowStyle CssClass=”data_set1″ />
<Columns>
<asp:TemplateField HeaderText=”Name” ItemStyle-HorizontalAlign=”left”>
<ItemTemplate>
<%#Eval(“DocumentName”).ToString()%>
<asp:HiddenField ID=”hdID” runat=”server” Value='<%# Eval(“CRD_ID”) %>’ />
</ItemTemplate>
<ItemStyle HorizontalAlign=”Left”></ItemStyle>
</asp:TemplateField>
<asp:BoundField DataField=”CreatedDate” HeaderText=”Date Date” SortExpression=”ModifiedDate”
DataFormatString=”{0:d}” />
<asp:BoundField DataField=”ModifiedDate” HeaderText=”Upload Date” SortExpression=”ModifiedDate”
DataFormatString=”{0:d}” />
<asp:TemplateField HeaderText=”Actions” ItemStyle-HorizontalAlign=”Left” ItemStyle-Width=”40px”>
<ItemTemplate>
<asp:ImageButton ID=”ImageButton1″ runat=”server” CommandArgument='<%# Eval(“UploadedDocument”) %>’
ImageUrl=”~/images/Download.jpg” CausesValidation=”False” OnClick=”ImageButton1_Click” />
</ItemTemplate>
<ItemStyle />
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
/// For Download Code
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
string _Name = ((ImageButton)sender).CommandArgument;
DownloadFile(_Name);
}
protected void DownloadFile(string name)
{
string folderPath = ConfigurationManager.AppSettings.Get(“DocumentPath”) + name; ;
string docPath = Request.PhysicalApplicationPath + folderPath;
System.IO.FileInfo _file = new System.IO.FileInfo(docPath);
if (_file.Exists)
{
Response.Clear();
Response.AddHeader(“Content-Disposition”, “attachment; filename=” + _file.Name);
Response.AddHeader(“Content-Length”, _file.Length.ToString());
Response.ContentType = “application/octet-stream”;
Response.WriteFile(_file.FullName);
Response.End();
}
//else
//{
// ClientScript.RegisterStartupScript(Type.GetType(“System.String”), “messagebox”, “<script type=\”text/javascript\”>alert(‘Sorry no image found’);</script>”);
//}
}