Markup page <!– ‘define control –> <asp:DropDownList ID=”MySelectionDDL” runat=”server” AutoPostBack=”True” AppendDataBoundItems=”true” DataSourceID=”MySelectionDS” DataTextField=”Text” DataValueField=”Value” OnDataBound=”MySelectionDDL_DataBound”> <!– ‘define datasource –> <asp:SqlDataSource ID=”MySelectionDS” runat=”server” ConnectionString=”< %$ ConnectionStrings:my_sql_connection %>” SelectCommand=”SELECT [Text], [Value] FROM [MyTable] ORDER BY [Text]”> </asp:SqlDataSource> Code behind Protected Sub MySelectionDDLDataBound(ByVal sender As Object, ByVal e As EventArgs) ‘add item at the beginning of the list […]
Archive for December, 2012
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 […]