Showing posts from June, 2012

ASP.NET HTML text input field get and set value

In our application if we use html text input field for jquery or like other as we need we can

Get the input field value :

<input type="text" name="std" id="datepicker5" />
in C#

string startDatepicker = String.Format("{0}", Request.Form["std"]);

Set the input Field :

<input type="text" id="datepicker5" value="<%= this.FromDate %>"/>
in C#

// declare a from attribute protected string FromDate { get; set; } protected void Page_Load(object sender, EventArgs e) { // setting value this.FromDate = DateTime.Now.ToShortDateString(); }

              Here it is important till now i not get any solution that set and get will work on same HTML text input field.

ASP.NET Jquery datepicker

In VS2010 the date time picker control is not available in toolbox. Their is only calender control. but if need to use date picker control in our form stylist j query date picker we can easily do it. let see some stylist datepicker from 

 You can also choose much more from . select which theme you want to use and download it. extract the zip file.  after extract you will see the file as like

we will use the css and the js folder data in our application.

Open visual studio 2010 select a new ASP.NET web application, after creating the project add the js and css from the downloaded file.

   In your master page head  show the reference of the js and css file and write the java script for .your i write 2 script named datepicker1 and datepicker2 for two datepicker control.

<head runat="server"> <title></title> <link href="~/Styles/Site.css" rel="styleshee…

ASP.NET Gridview cell value alignment

we can easily align our gridview cell value on load event like this

for (int i = 0; i < damageDetailsGridView.Rows.Count; i++) { damageDetailsGridView.Rows[i].Cells[0].HorizontalAlign = HorizontalAlign.Center; damageDetailsGridView.Rows[i].Cells[1].HorizontalAlign = HorizontalAlign.Left; damageDetailsGridView.Rows[i].Cells[2].HorizontalAlign = HorizontalAlign.Center; }
the output of the grid look like


how to remove time from datetime and display in a gridview

When we  load a Gridview from database value. by default it shows time with date in gridview column.
look like

if we want to show only date without the time then we have to add 2 property in column binding. HtmlEncode="False" DataFormatString="{0:d}"

The gridview aspx bind will be

<Columns> <asp:BoundField DataField="DistributorId" HeaderText="Distributor Id" /> <asp:BoundField DataField="Status" HeaderText="Status" /> <asp:BoundField DataField="ProductLine" HeaderText="Product Line" /> <asp:BoundField DataField="OrderID" HeaderText="Order Id" /> <asp:BoundField DataField="OrderDate" HeaderText="Order Date" HtmlEncode="False" DataFormatString="{0:d}" /> <asp:BoundField DataField="EmployeeId" H…

ASP.NET Dropdown item selected as my given value

if we want set the selected item of a drop down box from my given value we can use follow the code. here i am taking a gridview value and set it as selected item of the drop down. cosider the image

aspx :

Wing Dropdown :

<asp:DropDownList ID="regionWingDropDownList" runat="server" Height="30px" Width="217px" DataValueField="WingId" DataTextField="WingName" AutoPostBack="True" Style="margin-top: 0px" OnSelectedIndexChanged="regionWingDropDownList_SelectedIndexChanged"> </asp:DropDownList>
Division Dropdown

<asp:DropDownList ID="regionDivisionDropDownList" runat="server" Height="30px" DataValueField="DivisionId" DataTextField="DivisionName" Width="217px"> </asp:DropDownList>

Region Gridview

<asp:GridView ID="regionGridView" runat="ser…

ASP.NET Dropdown box event fire

Normally Dropdown box is not fire event. to fire any event of dropdown box you need to write the AutoPostBack="True" property in dropdown control.

ASPX File:

<asp:DropDownList ID="regionWingDropDownList" runat="server" Height="30px" Width="217px" DataValueField="WingId" DataTextField="WingName" AutoPostBack="True" style="margin-top: 0px" onselectedindexchanged="regionWingDropDownList_SelectedIndexChanged" > </asp:DropDownList>
protected void regionWingDropDownList_SelectedIndexChanged(object sender, EventArgs e) { Wing wing = new Wing(); wing.WingId = Convert.ToInt32(regionWingDropDownList.SelectedItem.Value); regionDivisionDropDownList.DataSource = _regionManagerObj.GetSelectedWingAllDiviSionName(wing); regionDivisionDropDownList.DataBind(); }

ASP.NET Gridview Column Hide

If you want to hide any column Of a grid you have hide it after load the grid.

Now i want to hide the id Column which contain 1,2,3,4.....

then the code will be on load event of the grid :

private void LoadDivisionGridData() { _divisionslist = new List<Division>(); _divisionslist = _divisionManagerObj.GetAllDivisionInfo(); divisionGridView.DataSource = _divisionslist; divisionGridView.DataBind(); ResetAllField(); divisionGridView.Columns[0].Visible = false; }

after hide the Id column it will be look life

 Thank you.

How to get ASP.NET Gridview selected row value

Gridview binding is one of the important to get selected row value from a Grid view. consider the following ASP.NET form i want to insert data that will save in SQL database and the Gridview will be load. Now i want when i will click on Select in Gridview button , selected row value will be load on Text field for update.

Class File:

public class Wing { public int WingId { get; set; } public string WingName { get; set; } public string WingCode { get; set; } }

Datagrid binding in aspx

<asp:GridView ID="wingsGridView" runat="server" Width="500px" AutoGenerateColumns="False" OnSelectedIndexChanged="wingsGridView_SelectedIndexChanged"> <Columns> <asp:BoundField DataField="WingId" HeaderText="Id" /> <asp:BoundField DataField="WingCode" HeaderText="Code" /> <asp:B…