Home » Posts tagged "ASP.NET" (Page 2)

Archive for the 'ASP.NET' Tag

Refresh page on button click

Markup page <script runat=”server”> Sub UpdateMessage(ByVal source As Object, ByVal e As SqlDataSourceStatusEventArgs) If e.AffectedRows > 0 Then ‘ Perform any additional processing, ‘ such as setting a status label after the operation. Page.Response.Redirect(Page.Request.Url.ToString(), True) End If End Sub ‘UpdateMessage </script> <asp:SqlDataSource ID=”ImgEditDS4″ runat=”server” ConnectionString=”< %$ ConnectionStrings:MyConnStr %>” SelectCommand=”SELECT [photo_id], [photo_1] WHERE ([photo_id] = @p_id)” […]

Define control properties in code behind located inside gridview or formview

Markup page <asp:FormView ID=”DefaultPhoto” runat=”server” DataKeyNames=”ge_id” DataSourceID=”ListPhotosDS”> <EditItemTemplate> <img src=”/images/< %# Container.DataItem("photo") %>” class=”detailsmallphoto”/> <asp:Label ID=”photo_idLabel” runat=”server” Text=’< %# Eval("photo_id") %>‘ Visible=”false” /> <asp:LinkButton ID=”UpdateButton” runat=”server” OnClientClick=”return confirm(‘Are you sure you want to remove this photo?’);” CommandName=”Update” /> </EditItemTemplate> </asp:FormView> Code behind DirectCast(DefaultPhoto.FindControl(“UpdateButton”), LinkButton).Text = “Remove” If Page.isPostBack Then DirectCast(DefaultPhoto.FindControl(“UpdateButton”), LinkButton).Text = “Add Photo” End […]

OleDbConnection string with ConfigurationManager

Web config <add name=”MyConnectionString” connectionString=”Data Source=SRV-MY-SQL\SQLCLSTR12; Initial Catalog=MyDatabaseName; Persist Security Info=True;User ID=MyUser;Password=MyPassword” providerName=”System.Data.SqlClient” /> Code behind or markup page ‘defines sql connection Dim connString As String connString = ConfigurationManager.ConnectionStrings(“MyConnectionString”).ToString Dim ConnDB As New OleDbConnection(“Provider=sqloledb;” & connString) ‘define oledbcommand Dim cmd As New OleDbCommand(“SELECT * _ “FROM my_table _ “WHERE name=’Mike’ ;”, ConnDB) Dim reader As […]