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
- 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” />
- 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() + 1End If
End Sub
- Add this in the GridView<asp:GridView ID=”GridView1″ runat=”server” AutoGenerateColumns=”False” DataKeyNames=”id”
- By using Container.DataItem
-
<asp:TemplateField> <ItemTemplate> <%# Container.DataItemIndex + 1 %> </ItemTemplate> </asp:TemplateField>
-
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.
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>
Dropdown List event not firing
Posted by: admin in .NET, Dropdown List on June 18th, 2010
Just make sure to set the AutoPostBack = true.
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.
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.
-
<defaultDocument>
-
<files>
-
<clear />
-
<add value="myhomepage.aspx" />
-
</files>
-
</defaultDocument>
This operation requires IIS integrated pipeline mode in ASPX
This error occurs when adding response header like this
-
Response.headers.add("header1", "value")
-
-
or Response.headers("header1") = "value"
-
-
instead, use the following t
-
-
Response.AddHeader("header1", "value")