asp.net dropdownlist – add blank line before db values

You can simply add a ListItem inside the DropDownList Markup. All the values from the DataSource will be appended after that. <asp:DropDownList ID=”drpClient” runat=”server” Width=”200px” AutoPostBack=”True” DataSourceID=”dsClients” DataTextField=”name” DataValueField=”client_id” AppendDataBoundItems=”true”> <asp:ListItem>– pick one –</asp:ListItem> </asp:DropDownList>

asp.net radio button grouping

I finally got around this by creating a plain radio button and setting the value using an server-side eval. <input type=”radio” name=”radCustomer” value=”<%#Eval(“CustomerNumber”) %>” /> Now when the application performs a postback, I check for the value of Request.Form[“radCustomer”]. This works flawlessly.

Could not load file or assembly Exception from HRESULT: 0x80131040

Finally found the answer!! Go to References –> right cilck on dll file that causing the problem –> select the properties –> check the version –> match the version in properties to web config <dependentAssembly> <assemblyIdentity name=”YourDllFile” publicKeyToken=”2780ccd10d57b246″ culture=”neutral” /> <bindingRedirect oldVersion=”0.0.0.0-YourDllFileVersion” newVersion=”YourDllFileVersion” /> </dependentAssembly>

Conditionally hide CommandField or ButtonField in Gridview

First, convert your ButtonField or CommandField to a TemplateField, then bind the Visible property of the button to a method that implements the business logic: <asp:GridView runat=”server” ID=”GV1″ AutoGenerateColumns=”false”> <Columns> <asp:BoundField DataField=”Name” HeaderText=”Name” /> <asp:BoundField DataField=”Age” HeaderText=”Age” /> <asp:TemplateField> <ItemTemplate> <asp:Button runat=”server” Text=”Reject” Visible=”<%# IsOverAgeLimit((Decimal)Eval(“Age”)) %>” CommandName=”Select”/> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> Then, in the code … Read more

Jquery Hidden Field

Because jQuery knows nothing about asp:HiddenField. It looks in the HTML structure where you have <input type=”hidden” name=”ctl00$cph_main$HiddenFieldServerDateTime” id=”ctl00_cph_main_HiddenFieldServerDateTime” …. So there’s no input with ID= HiddenFieldServerDateTime. There are a few ways to overcome this: Use a css selector: <asp:HiddenField ID=”HiddenFieldServerDateTime” runat=”server” CssClass=”SomeStyle” /> with the following selector: var serverDateTime = $(“.SomeStyle”).val(); CssClass is not … Read more

ASP MVC Authorize all actions except a few

Ok, this is what I did. If there is a better way let me know. public class NotAuthorizeAttribute : FilterAttribute { // Does nothing, just used for decoration } public class BaseController : Controller { protected override void OnActionExecuting(ActionExecutingContext filterContext) { // Check if this action has NotAuthorizeAttribute object[] attributes = filterContext.ActionDescriptor.GetCustomAttributes(true); if (attributes.Any(a => … Read more

how do I detect user operating system

Here’s what I came up with and it seems to work fairly well: public String GetUserEnvironment(HttpRequest request) { var browser = request.Browser; var platform = GetUserPlatform(request); return string.Format(“{0} {1} / {2}”, browser.Browser, browser.Version, platform); } public String GetUserPlatform(HttpRequest request) { var ua = request.UserAgent; if (ua.Contains(“Android”)) return string.Format(“Android {0}”, GetMobileVersion(ua, “Android”)); if (ua.Contains(“iPad”)) return string.Format(“iPad … Read more

ReportViewer Control – Height issue

This is the way I fixed, take a look <div style=”Width:auto;”> <form id=”form1″ runat=”server” style=”width:100%; height:100%;”> <asp:ScriptManager ID=”ScriptManager1″ runat=”server”> </asp:ScriptManager> <rsweb:ReportViewer ID=”rptViewer” runat=”server” Width=”100%” Height=”100%” AsyncRendering=”False” SizeToReportContent=”True”> </rsweb:ReportViewer> </form></div> The thing doing the magic is AsyncRendering=”False” SizeToReportContent=”True” the rest is basic HTML. The report will be displayed as it was designed. There might be some … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)