Tuesday, May 29, 2012

Hyperlink in gridview item template in c#

1.Add this code to aspx page


<asp:GridView ID="GVClientCaseList" runat="server" AutoGenerateColumns="False"
                                Width="781px" BorderWidth="1px" GridLines="None" CssClass="inputSubmitBtnPrpl_2"
                                PagerSettings-Mode="Numeric" AllowPaging="True" PageSize="20"
                                AllowSorting="True"
                    onpageindexchanging="GVClientCaseList_PageIndexChanging"  >
                                <RowStyle BackColor="#E9E6F0" ForeColor="#4A3C8C" />
                                <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
                                <Columns>
   
               
               
                <asp:TemplateField HeaderText="Survey">
                                    <ItemStyle HorizontalAlign="Center" />
                                    <ItemTemplate>
                                        <asp:HyperLink ID="hlUrlNA" runat="server" NavigateUrl='<%#FormatUrlSurvey(Eval("WarrantID"))%>'
                                            Text='<%# Eval("WarrantID")%>'>
                                        </asp:HyperLink>
                                    </ItemTemplate>
                                </asp:TemplateField>          

                                 
                                    <asp:BoundField DataField="WarrantID" HeaderText="Fullref">
                                        <HeaderStyle ForeColor="White" Width="15%" />
                                        <ItemStyle HorizontalAlign="left" CssClass="alignGridText"></ItemStyle>
                                    </asp:BoundField>
                                    <asp:BoundField DataField="ClaimantName" HeaderText="Claimant" ItemStyle-HorizontalAlign="center"
                                        ItemStyle-CssClass="alignGridText" ReadOnly="true">
                                        <HeaderStyle ForeColor="White" />
                                        <ItemStyle HorizontalAlign="Center" CssClass="alignGridText"></ItemStyle>
                                    </asp:BoundField>
                                    <asp:BoundField DataField="DefendantName" HeaderText="Defendant" ItemStyle-HorizontalAlign="center"
                                        ItemStyle-CssClass="alignGridText" ReadOnly="true">
                                        <HeaderStyle ForeColor="White" />
                                        <ItemStyle HorizontalAlign="Center" CssClass="alignGridText"></ItemStyle>
                                    </asp:BoundField>
                                   
                                </Columns>
                            </asp:GridView>


2.In Code behind page add this function


  protected string FormatUrlSurvey(object cid)
    {
        return "CaseDetails.aspx?WarrantID=" + cid.ToString();

    }


How set value to dropdownlist with JavaScript

<script language="javascript" type="text/javascript">

 function setDropDownList(elementRef, valueToSetTo)
                 {
                          var isFound = false;
   

                        for (var i=0; i<elementRef.options.length; i++)
                        {
                              if ( elementRef.options[i].value.toLowerCase() == valueToSetTo.toLowerCase() )
                              {
                               elementRef.options[i].selected = true;
                               isFound = true;
                              }
                         }


                         if ( isFound == false )
                       elementRef.options[0].selected = true;
             }
           
             function setDatosCGA(PaymentMethod)
                {
                       setDropDownList(window.opener.document.getElementById('ctl00_PageContent_ddlPyamentMehtod'), PaymentMethod);
                     
                 }

</script>

Monday, May 7, 2012

adding double quotes with variable value or property value

 lblError.Text = "We have checked into the system and found that you have already uploaded the "+ string.Format("\"{0}\"", objTranscription.pOriginalFileName)+ " file into the Shertalk system. This may be the same file you have uploaded earlier hence can be duplicated. Please review and try again.";

Thursday, May 3, 2012

Code for zipping files in asp.net


         {

             byte[] buffer = new byte[4096];

             
             // the path on the server where the temp file will be created!

             var tempFileName = Server.MapPath(@"TempFiles/" + Guid.NewGuid().ToString() + ".zip");

             var zipOutputStream = new ZipOutputStream(File.Create(tempFileName));

             var filePath = String.Empty;

             var fileName = String.Empty;

             var readBytes = 0;

             foreach(GridViewRow row in gvFiles.Rows)

             {

                 var isChecked = (row.FindControl("chkSelect") as CheckBox).Checked;

                 if (!isChecked) continue;

                 filePath = (row.FindControl("lblFilePath") as Label).Text;

                 fileName = (row.FindControl("lblFileName") as Label).Text;

                 var zipEntry = new ZipEntry(fileName);

                 

                 zipOutputStream.PutNextEntry(zipEntry);

                 using(var fs = File.OpenRead(filePath))

                 {

                     do

                     {

                         readBytes = fs.Read(buffer, 0, buffer.Length);

                         zipOutputStream.Write(buffer,0,readBytes);

                     } while (readBytes > 0);

                 }

             }

             if (zipOutputStream.Length == 0)

             {

                 lblMessage.Text = "Please select at least one file!";

                 return;

             }

             zipOutputStream.Finish();

             zipOutputStream.Close();

             Response.ContentType = "application/x-zip-compressed";

             Response.AppendHeader("Content-Disposition", "attachment; filename=YourFile.zip");

             Response.WriteFile(tempFileName);

             Response.Flush();

             Response.Close();

             // delete the temp file

             if(File.Exists(tempFileName))

                 File.Delete(tempFileName);

         }

Tuesday, May 1, 2012

How to Resolve SSRS Deploye error

Use the following command for configuring SSRS

c:\>rsconfig -c -s ServerName -d reportserver -a SQL -u sa -p sa