w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
how to bind ASP.Net DropDownList control in EditItemTemplate of GridView on edit(imagebutton)click
protected void gv_RowDataBound(object sender, GridViewEditEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if ((e.Row.RowState & DataControlRowState.Edit) > 0) { DropDownList DStatusEdit= (DropDownList)e.Row.FindControl("DStatusEdit"); DataTable dt = con.GetData("select distinct status from directory"); DStatusEdit.DataSource = dt; DStatusEdit.DataTextField = "status"; DStatusEdit.DataValueField = "status"; DStatusEdit.DataBind(); DataRowView dr = e.Row.DataItem as DataRowView; DStatusEdit.SelectedValue = dr["columnname"].ToString(); } } } } protected void gv_RowEditing(object sender, GridViewEd

Categories : C#

Bind Kendoui dropdownlist to mvvm data-bind value
Found the solution, here's the working code. @Html.Kendo().DropDownList().BindTo(new SelectList(ViewBag.HotelStatuses, "Id", "Name")).Name("ddl-hotel-status").HtmlAttributes(new Dictionary<string, object>{{"data-bind", "value: dataItem.HotelStatusId"}})

Categories : Kendo Ui

How to add Data To GridView From TextBox & DropDownList
Put another button to insert data into database and write below code on click event. protected void Button2_Click(object sender, EventArgs e) { foreach (GridViewRow oItem in GridView1.Rows) { string str1 = oItem.Cells[0].Text; string str2 = oItem.Cells[1].Text; string str3 = oItem.Cells[2].Text; insertData(str1, str2, str3); } } public void insertData(string str1,string str2,string str3) { SqlConnection cn = new SqlConnection("Your Connection strig"); string sql = "insert into tbl1 (column1,column2,column3) values ('" + str1 + "','" + str2 + "','" + str3 + "')"; SqlCommand cmd = new SqlCommand(sql, cn); cmd.ExecuteNonQuery(); } Thanks

Categories : C#

How do I use a DropDownList in a Gridview Edit Template when the selected value does not mirror sql data?
You don't need to do this in code; the ListItem has both a Text and a Value property: <asp:DropDownList ID="ddlDay" runat="server" SelectedValue='<%# Bind("Day") %>'> <asp:ListItem Value="1" Text="Monday" /> <asp:ListItem Value="2" Text="Tuesday" /> <asp:ListItem Value="3" Text="Wednesday" /> <asp:ListItem Value="4" Text="Thursday" /> <asp:ListItem Value="5" Text="Friday" /> <asp:ListItem Value="6" Text="Saturday" /> <asp:ListItem Value="7" Text="Sunday" /> </asp:DropDownList> The SelectedValue will return the day number, and the list will display the day name.

Categories : C#

Export Gridview Data to Excel in ASP.NET Linq data bind
It's pretty easy to set up the excel export that will export only the gridview. This has been tested and will only export the gridview that appears on your given web page. For your C# code use the following: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class vxcel_export : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button2_Click(object sender, EventArgs e) { Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=file-name.xls"); Response.ContentType = "application/vnd.xlsx"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); Sys

Categories : Asp Net

Bind dropdownlist based on the selected value of another dropdownlist
If you want to use ajax control toolkit then here is the link http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/CascadingDropDown/CascadingDropDown.aspx Else you want to fill it from jquery or javascript here is the link http://www.mikesdotnetting.com/Article/97/Cascading-DropDownLists-with-jQuery-and-ASP.NET But if you go with the second link then you will have some security issue. Invalid postback or callback argument. When dropdown list populated with jquery and there is a postback

Categories : Javascript

Bind gridview using jquery : Have table data clickable
You are closing the anchor element in your code twice... <a href="#" onclick="getStock()" value=' + codes + ' />' + codes + '</a> Should be: <a href="#" onclick="getStock()" value=' + codes + '>' + codes + '</a> (note the removed "/" right before the anchor's greater-than character)

Categories : Javascript

sort and page result of data bind with eval by gridview
hi guys i did i did it by creating new sells and give them cssclass` int j = 0; protected void grid_advertise_1_RowDataBound(object sender, GridViewRowEventArgs e) { if (j<=1) { myConnection c = new myConnection(); SqlDataAdapter da = new SqlDataAdapter("select * from TblArticleWishka where ID>=0 ", c.Cnn); DataSet ds = new DataSet(); da.Fill(ds); int i = 1; foreach (DataRow dr in ds.Tables[0].Rows) { i++; TableCell a = new TableCell(); a.CssClass = "advertise_1_" + i + ""; a.Text = (string)dr["TitleEn"]; e.Row.Cells.Add(a); a.DataBind(); } j++; } }`

Categories : C#

Retrieve data from database and store in string and bind all the strings to gridview
You can loop through your DataTable returned from your stored procedure in the database, like this: // Iterate through the columns of the DataTable to set the BoundFields dynamically foreach (DataColumn theDataColumn in theDataTable.Columns) { // Instantiate new BoundField BoundField theBoundField = new BoundField(); // Set the DataField value theBoundField.DataField = theDataColumn.ColumnName; // Set the HeaderText value theBoundField.HeaderText = theDataColumn.ColumnName; // Add BoundField to the GridView GridView1.Columns.Add(theBoundField); }

Categories : Asp Net

DropDownList in GridView
There are some built-in functions will help you to do all of this. 1)About loading elements from database each row,this will not happen you can load data only once and insert it into DataTable and set Datasource of each grid row ddl to that DataTable How? there is a function called OnRowDataBound ,every row being inserted inside the gridview will go to this function here you can find the drop down list and set its listitem from the datatable. DataTable dt_Category = new DataTable(); protected void Page_Load(object sender, EventArgs e) { using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStringDb1"].ToString())) { try { String cmdText = "SELECT CategoryName FROM Category"; SqlCommand cmd = new SqlCommand

Categories : C#

Create a DropDownList in GridView Asp.NET
private void BindGrid() { DataTable dt = new DataTable(); dt.Columns.Add("Test DropDown"); Control container = new Control(); TemplateField tf = new TemplateField(); string chkRole = "ddlTest"; tf.ItemTemplate = new CreateDropDownList(chkRole); //tf.HeaderText = dt.Columns[i].ColumnName; this.gvDDL.Columns.Add(tf); gvDDL.DataSource = dt; gvDDL.DataBind(); } } public class CreateDropDownList:ITemplate { string checkboxID; public CreateDropDownList(string id) { this.checkboxID = id; // // TODO: Add constructor logic here // } public void InstantiateIn(Control container) { DropDownList ddl = new DropDownList(); ddl.ID = chec

Categories : C#

How do I bind a DropDownList after postback?
You should set the 'OnSelectedIndexChanged' event. <asp:DropDownList ID="dd1" runat="server" AutoPostBack="True" onselectedindexchanged="ddlItemSelected" EnableViewState="True"> <asp:ListItem Value="10">10</asp:ListItem> <asp:ListItem Value="20">20</asp:ListItem> <asp:ListItem Value="30">30</asp:ListItem> </asp:DropDownList> protected void ddlItemSelected(object sender, EventArgs e) { //Add your selected value to viewstate or session or whatever. Then check this value when binding on postback. Viewstate["myValue"] = dd1.SelectedValue; }

Categories : C#

Getting row of selected DropDownList in GridView cells
You can find the grid view row by finding the grandparent (.Parent.Parent) of your drop down list, because the drop down list is within a cell of the row, which is a part of the row itself, so you need to go two levels up, like this: protected void chooseThemeTypeDropDown_OnSelectedIndexChanged(object sender, EventArgs e) { DropDownList chooseThemeTypeDropDown = sender as DropDownList; if (chooseThemeTypeDropDown != null) { System.Diagnostics.Debug.WriteLine(chooseThemeTypeDropDown.SelectedItem.Value.ToString()); GridViewRow row = (GridViewRow)chooseThemeTypeDropDown.Parent.Parent; } }

Categories : C#

DropDownList in autogenerated rows of GridView
GridView RowDataBound event is where you want to access individual items in a row as they are being bound to the grid. protected void GridView_People_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { // Find the particular drop down list for this row DropDownList ddl = (DropDownList)e.Row.FindControl("DropDown_features"); // Go get data and do whatever you need to do to the drop down list } } Note: You will need to add an attribute for the RowDataBound event in the markup for your GridView, like this: onrowdatabound="GridView_People_RowDataBound"

Categories : Asp Net

Prevent duplicate data from appear in another dropdownlist when it is selected by another dropdownlist
You can use Cache to achieve this.Like this protected void bindDdls() { DataTable dt = new DataTable(); try { ddlpid1.Items.Clear(); ddlpid2.Items.Clear(); using (var connAdd = new SqlConnection("Data Source = localhost; Initial Catalog = MajorProject; Integrated Security= SSPI")) { connAdd.Open(); var sql = "Select policeid from PoliceAccount where status ='available' and handle ='offcase' and postedto='" + ddllocation.SelectedValue + "'"; using (var cmdAdd = new SqlDataAdapter(sql, connAdd)) { DataSet ds2 = new DataSet(); cmdAdd.Fill(ds2); dt = ds.Tables[0]; if (dt.Rows.Count > 0) { ddlpid1.DataSource = d

Categories : C#

bind many dropdownlist in a continous fashion
If your drop down lists are added to the mark-up you can simply do the following: protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { for(int i=1;i<=10;i++) { var ddl = FindControl("ddlxx" + i) as DropDownList; if (ddl != null) { BindDropDown(ddl); } } } } private void BindDropDown(DropDownDataList ddl) { ddl.DataSource = Prod.GetValues(); ddl.DataTextField = "ComponentID"; ddl.DataValueField = "ComponentName"; ddl.DataBind(); }

Categories : C#

bind dropdownlist return null value
The DropDownList is inside EditItemTemplate, so it is only available when the grid is in edit mode. Change your code : if (e.Row.RowType == DataControlRowType.DataRow) to this: if (e.Row.RowType == DataControlRowType.DataRow && workingdaygrid.EditIndex > -1) and it should work.

Categories : Asp Net

filter gridview based on dropdownlist selected value
You are not showing where you initialize idTeacher. However, you have to DataBind the GridView in ASP.NET after you have assigned the DataSource: GridView1.DataSource = table; GridView1.DataBind(); // <-- this is missing in your code You should use sql-parameters anyway, otherwise you are potentially open for sql-injection and you should use the using statement to ensure that all unmanaged resources are disposed (even on error): using (var con = new OleDbConnection("ConnectionString")) using (var da = new OleDbDataAdapter("select * from teacher where idteacher=@idTeacher", con)) { da.SelectCommand.Parameters.AddWithValue("@idteacher", idTeacher); DataTable table = new DataTable(); da.Fill(table); // opening or closing connection not needed, done by Fill GridView1.D

Categories : C#

How do I set dropdownlist selectedvalue in edit mode but not in gridview?
You have to use TemplateField and within that template you can specify your layout, which could contain multiple fields, and use different controls for Edit/Insert operations, like in the following sample: Listing 1. <asp:TemplateField HeaderText="Toll-Free: Area/Phone #"> <ItemTemplate> ( <%# DataBinder.Eval( Container.DataItem, "A_TollFree_AreaCode" )%> ) <%# DataBinder.Eval(Container.DataItem, "A_TollFree_Number")%> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txtAreaCode" runat="server" CssClass="phoneAreaCode" MaxLength="3" Text='<%# Bin

Categories : Asp Net

Cannot Access DropdownList in EditItemTemplate inside Gridview
The RowEditing event just gives the row index being edited. You need to set the edit row index to the grid and rebind it. And if you need to set a value or need to bind a control inside EditItemTemplate you have to do it in RowDateBound event, as you will be re-binding grid in RowEditing event so the RowDataBound event will also give you the EditItemTemplate's controls. As shown in this answer protected void gv_RowEditing(object sender, GridViewEditEventArgs e) { // grid view's edit index has been changed so rebind it gv.EditIndex = e.NewEditIndex; } protected void gv_RowDataBound(object sender, GridViewEditEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if ((e.Row.RowState & DataControlRowState.Edit) > 0) { ddList.SelectedValue

Categories : Asp Net

populating DropDownList in a gridview with array elements
You could simply loop it and add the ListItems programmatically: DropDownList drd = (DropDownList)GridView1.FindControl("DrdDatabase"); foreach(string colName in mylist) drd.Items.Add(new ListItem( colName )); However, are you sure that you find your DropDownList via GridView1.FindControl? I assume you get a NullRefernceException there. Then you need to show us where it actually is. If it is in a TemplateField of the GridView you should use the RowDataBound event: private ArrayList ExcelData { get { object excel = Session["exceldata"]; if (excel == null) Session["exceldata"] = new ArrayList(); return (ArrayList)Session["exceldata"]; } set { Session["exceldata"] = value; } } protected void GridView2_RowDataBound(object sender, GridVi

Categories : C#

How dropdownlist bind with slqdatasource retrieve proper value?
i haven't used the sqldatasource object in awhile so forgive me, but are you missing something simple like not binding the control to the datasource object. Perhaps your parameter isn't being set properly. Do you have access to SQL Profiler? Check and see if your query is running and running with the right query ... also a side note ... this prob isn't it but your dropdown's id ="ddlPayBy2" but you're checking if (ddlPayBy.selected....

Categories : C#

How to Bind DropDownList with a Select result of List
var list = countryRegionList.Select(o => o.CountryCode).Distinct(); This will return a collection of just the CountryCode property, which I'm assuming is a string, therefore there is no CountryCode property on a string to bind to. You want a DistinctBy, or use an anonymous type in your projection: var list = countryRegionList.Select(o => new { o.CountryCode }).Distinct(); Note that new { o.CountryCode } is shorthand for new { CountryCode = o.CountryCode }

Categories : C#

Set selected value or text for DropDownList in edit mode of gridview asp.net
I mean when I put my grid view in Edit mode, I don't want my Dropdownlist show "--Select Zone Name--". I want it show "text 1",2,3 or 4...which is displaying in my Label in View mode. And you can do this in Gridview_RowEditing event. See the code below: protected void Gridview_RowEditing(object sender, GridViewEditEventArgs e) { Label lbDisplayName = (Label)Gridview.Rows[e.NewEditIndex].FindControl("lbDisplayName"); string name = lbDisplayName.Text; GridViewRow gvr = Gridview.Rows[e.NewEditIndex]; var dr = (DropDownList)gvr.FindControl("ddlName"); dr.SelectedItem.Text = name; }

Categories : Asp Net

While Editing the GridView, dropdownlist values are not storing in the variable
Try likes this , GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex]; DropDownList ct = (DropDownList)row.Cells[2].FindControl("DropDownList6"); string ctype = ct.SelectedValue; DropDownList cs = (DropDownList)row.Cell[3].FindControl("DropDownList3"); string cstatus = cs.SelectedValue;

Categories : C#

How to set Eval("DropDownList.SelectedItem.text") programmatically to gridview in asp.net c#
In .aspx '<%# DropDownList2.SelectedItem.Text %>' WITHOUT the Eval Or DoubleQuotes. you are just exposing server-side control property and you don't need to use Eval as you are not evaluating an expression from a bound Data-item. You can also use the RowCreated event or RowDataBound for your gridview : protected void MyGrid_RowCreated(object sender, GridViewRowEventArgs e) { //DoWhatever you Need TextBox t = e.Row.Cells[4].FindControl("subject") as TextBox; t.Text = DropDownList2.SelectedItem.Text; }

Categories : Asp Net

Postback resets the selectedValue of DropdownList inside GridView
RowDataBound gets fired every time (irrespective of whether the page is PostBack page or NOT). You need to add that if(!IsPostBack) condition around the code where you are performing the databinding for the dropdowns in your RowDataBound event.

Categories : C#

Filter dropdownlist in gridview based on form parameter
http://asimsajjad.blogspot.in/2009/09/raising-dropdownlist.html DropDownList SelectedIndexChanged within Gridview not firing!

Categories : Asp Net

how to bind model value to selected item text from dropdownlist mvc4
When you define a dropdown list in Html, each option has an attribute for value and text the text value is shown to the user and the value is the "selected value" of that dropdown. When the form is posted to the controller, only the value is posted. If you wish to have the name instead of the Id to post, simply set the value attribute of the dropdown list items to the name of the source data. For example, when you populate your state dropdown you could do it like this: $("#State").append($("<option></option>").val(Region.Name).html(Region.Name));

Categories : C#

javascript file unbinding from dropdownlist on partial post back - need to re-bind
Found a pure CSS solution to my original problem which was styling the dropdownlist. I wrapped my ddl in a label <label class="dropDownArrow" style="width:100%;"> <asp:DropDownList ID="f_Nights" runat="server" CssClass="inputComboHomePage" AutoPostBack="True" OnSelectedIndexChanged="f_Nights_SelectedIndexChanged"> <asp:ListItem Text="Number of Nights" Value="1" Selected="True"></asp:ListItem> <asp:ListItem Text="2" Value="2"></asp:ListItem> </asp:DropDownList> </label> And then applied the following css .dropDownArrow { position: relative; display: inline-block; } /* Select arrow styling */ .dropDownArrow:after { content: ''; width: 26px; height: 26px; position: absolute; di

Categories : C#

display gridview data in another page or other gridview with row data in editable mode
You need to add RowCommand Event in GridView. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand"> <asp:LinkButton ID ="lnkEdit" runat ="server" CommandArgument='<%#Eval("Recordid")%>' CommandName ="cmdEdit" Text ='Edit'></asp:LinkButton> </asp:GridView> Here rocordid is the id of your record. In Page behind you need to write code. protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "cmdEdit") { string Recordid = Convert.ToString(e.CommandArgument.ToString()); Response.Redirect("EditPage.aspx?recordid="+Recordid ); } } On EditPage you can get recordid from the query string and can fetch the record form the datab

Categories : Asp Net

Gridview returning empty even when there is data. I want to use data in the gridview to update another database
Per my comment above you may want to do something like: List<string> _OrderIds = new List<string>(); DataTable table = gvOrderLines.DataSource as DataTable; foreach (GridViewRow gvr in table.Rows) { Label myOrderIDLablel = (Label)gvr.FindControl("lblOrderID"); //find control since it is a template field _OrderIds.Add(myOrderIDLablel.Text); } I hope this get you headed in the right direction.

Categories : C#

SqlDataSource makes DropdownList results to one item that is duplicated in the list for displaying in GridView
You've defined your DropDownList in the following way: <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="ProblemDataSource" DataTextField="SkillGroup" DataValueField="SkillGroup"> <asp:ListItem Selected="True">Hardware</asp:ListItem> <asp:ListItem Selected="True">Software</asp:ListItem> <asp:ListItem Selected="True">Network</asp:ListItem> </asp:DropDownList> For a start, you can't have all items selected. Only Hardware will be selected as it's the first in the list. This leads to your second problem; The query you then run is (reduced for brevity): SELECT blah FROM Tables WHERE ([SkillGroup] = @SkillGroup) Which, of course, will be Hardware in your example above.

Categories : Asp Net

Null Exception thrown in dropdownlist selected value inside gridview on button click
If you have a header row, it will always be at the index 0, so you can't test for it not being the header row and having an index of 0, as both checks will return false. Change your index in both your check for adding the DDL, and the code to fetch it. Adding code: if (e.Row.RowType == DataControlRowType.DataRow) { DropDownList ddl; if (e.Row.RowIndex == 1) { // ..... } } Fetching code: GridViewRow row = dgData.Rows[1]; DropDownList ddl = (DropDownList)row.Cells[1].FindControl("ddlCol1");

Categories : C#

All the values from database on page load in dropdownlist to be bind and default value to be selected which can be chaged after updation
On pageload use a select query then check the row count example : if (dtCheck.Rows.Count > 0)<br> { if (!IsPostBack)<br> { ddlAnswers.SelectedValue = dtCheck.Rows[0] ["columnname"].ToString() } } Note; if(!IsPostBack) is used so that if you update the database using client side it will not retrieve the selected value in the drop down during page load

Categories : C#

how to bind substring into gridview and
If you have an entity that you bind to your gridview, you can do this: First, add a new property: [NotMapped] public string CutDescription { get { if (Description.Length <= 1000) { return Description; } return Description.Substring(0, 1000) + "..."; } } Then you can bind this to your gridview: <asp:BoundField DataField="CutDescription" HeaderText="Description" /> This is just one way to do it. Hope it helps. EDIT: Another way using RowDatabound event: protected void Grid_RowDataBound(object sender, GridViewRowEventArgs e) { var row = e.Row; if (row.RowType == DataControlRowType.DataRow) { // Just change the index of the cell var description = row.Cells[1].Text; if (description.Len

Categories : Asp Net

How to bind MembershipUsersCollection to GridView
The MembershipUserCollection implements IEnumerable but not IEnumerable so we have to cast the result and then transform that in a IQueryable: public IQueryable<System.Web.Security.MembershipUser> GridView1_GetData() { return Membership.GetAllUsers().Cast<MembershipUser>().AsQueryable<MembershipUser>(); }

Categories : C#

How do we bind gridview with list of objects?
Do you expect your code fragment to be working and need help locating the problem, or are you asking how to code data binding and data aggregation in xaml/c# code? Your code is not complete and will not work. You need to perform an add operation to the list on button click which you can pull the input from text boxes. If you need the list data to reflect on to your xaml/display, you need to add notifier to trigger the UI to refresh on data change. You can learn how to do two way data binding properly from the Data-Binding sample code.

Categories : C#

WPF ListView-GridView : bind image
You can use a Data Binding ValueConverter for this Your converter class - public class MyImageConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { string imageName = (string) value; return new BitmapImage(new Uri("../../images/" + imageName + ".png", UriKind.Relative)); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } In your code-behind foreach (KeyValuePair<string, string> Column in Columns) { GridViewColumn gvc = new GridViewColumn(); Binding binding = new Binding(Column.Key); if (Column.Key == "Image") {

Categories : C#

Is this the correct way to bind a textbox to a gridview?
In-line SQL is not secure, you are vulnerable to SQL injection, because something extremely harmful to your database could be typed into that text box and there is not checking of that value. Read Understanding SQL Injection and Creating SQL Injection Proof ASP.NET Applications Use parameterized SQL or stored procedures inside of SQL Server.

Categories : Asp Net



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.