Posts Tagged ‘aspx’

How to Display the Row Index of the GridView in ASPX

There are 3 ways to display the row index of the GridView

  1. By Using the SQL Select Statement
    • SELECT Row_Number() OVER(order by id) as rowID, [mycol1], [mycol2], [id] FROM [Table1]
    • In the gridview, <asp:BoundField DataField=”Rowid” HeaderText=”Rowid”  ReadOnly=”True” SortExpression=”Rowid” />
  2. By Using RowCreated Event of the GridView
    • Add this in the GridView<asp:GridView ID=”GridView1″ runat=”server” AutoGenerateColumns=”False” DataKeyNames=”id”
      DataSourceID=”SqlDataSource1″ OnRowCreated=”GridView1_RowCreated1″ >

      <Columns>
      <asp:TemplateField HeaderText=”myRowid”>
      <ItemTemplate><asp:Label runat=”server” />
      </ItemTemplate>
      </asp:TemplateField>

    • Add this EventProtected Sub GridView1_RowCreated1(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
      If e.Row.RowType = DataControlRowType.DataRow Then

      ‘ Retrieve the Label from the first column.
      Dim myLabel As Label = CType(e.Row.Cells(0).Controls(0), Label)

      ‘ Set Label text equal to the rowIndex +1
      myLabel.Text = e.Row.RowIndex.ToString() + 1

      End If
      End Sub

  3. By using Container.DataItem
    • <asp:TemplateField>
          <ItemTemplate>
              <%# Container.DataItemIndex + 1 %>
          </ItemTemplate>
      </asp:TemplateField>

Source

, , ,

No Comments


Publish Failed

Publishing of a web site is a very easy tasks but the tricky part is when you get this error “PUBLISH FAILED” but it did compiled successfully. One way to get this problem solved is to look the OUPUT WINDOW and you will have what you need to do.

, ,

No Comments


Nested Update Panel

Set the UpdateMode to Conditional to create a nested update panel , so that the parent update panel will not get refreshed when the child is being refreshed.

<pre lang=”vb.net”>

<form id=”form1″ runat=”server”>

<asp:ScriptManager ID=”ScriptManager1″ runat=”server”>

</asp:ScriptManager>

<div>

<table width=”80%” border=”3″>

<tr>

<td>

Label outside all the Update Panels

<asp:Label ID=”Label3″ runat=”Server” Font-Bold=”true”></asp:Label>

<br />

<br />

<asp:Button ID=”Button3″ runat=”Server” Text=”Refresh” />

<br />

<br />

</td>

</tr>

<tr>

<td>

<table width=”65%” border=”2″>

<tr>

<td>

<asp:UpdatePanel ID=”UpdatePanel1″ runat=”server” UpdateMode=”Conditional”>

<ContentTemplate>

Label within the Parent Update Panel

<asp:Label ID=”Label1″ runat=”server” Font-Bold=”true”></asp:Label>

<br />

<br />

<asp:Button ID=”Button1″ runat=”server” Text=”Refresh” />

<table width=”40%” border=”1″>

<tr>

<td>

<asp:UpdatePanel ID=”UpdatePanel2″ runat=”server” UpdateMode=”Conditional”>

<ContentTemplate>

<br />

<br />

Label within the Child Update Panel

<asp:Label ID=”Label2″ runat=”server” Font-Bold=”True”></asp:Label>

<br />

<br />

<asp:Button ID=”Button2″ runat=”server” Text=”Refresh” />

</ContentTemplate>

</asp:UpdatePanel>

</td>

</tr>

</table>

</ContentTemplate>

</asp:UpdatePanel>

</td>

</tr>

</table>

</td>

</tr>

</table>

</div>

</form>

Code behind

protected void Page_Load(object sender, EventArgs e)

{

Label1.Text = System.DateTime.Now.ToString();

Label2.Text = System.DateTime.Now.ToString();

Label3.Text = System.DateTime.Now.ToString();

}

</pre>

<a href=”http://geekswithblogs.net/ranganh/archive/2007/05/16/112525.aspx”>Source</a>

, ,

No Comments


Dropdown List event not firing

Just make sure to set the AutoPostBack = true.

, ,

No Comments


The event of the Dynamic creation of the control does not work

You need to recreate the created control and attach the events every page load.

, , , ,

No Comments


How to set default document using web.config

To set the default document of the web site using web.config, add the following lines inside the system.webServer.

  1. <defaultDocument>
  2.  <files>
  3.    <clear />
  4.    <add value="myhomepage.aspx" />
  5.  </files>
  6. </defaultDocument>

Read more

, ,

No Comments


This operation requires IIS integrated pipeline mode in ASPX

This error occurs when adding response header like this

  1. Response.headers.add("header1", "value")
  2.  
  3. or Response.headers("header1") = "value"
  4.  
  5. instead, use the following t
  6.  
  7. Response.AddHeader("header1", "value")

, ,

No Comments



SetPageWidth