I have an ext.net v2.5 combobox and im trying to databind the combobox in server side onload the asocieted store with .net datatable but is not working.
Any ideas how these can be done. databinding datatable to combobox?
<ext:ComboBox ID="ddlProduct" runat="server" ValueField="IDProduct" DisplayField="ProductName" FieldLabel="Product" LabelWidth="50" Width="250">
<Store>
<ext:Store runat="server" ID="ddlProductStore">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="IDProduct" />
<ext:ModelField Name="ProductName" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>
Server Side Code:
ddlProductStore.DataSource = MyApp.Data.DataRepository.Provider.ExecuteDataSet("sp_GetSegmentProducts ", 1).Tables(0)
ddlProductStore.DataBind()
It appears to be working well with a DataTable in the test below. So, I assume the DataTable on your side doesn't have required Columns.
<%# Page Language="C#" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
DataTable dataTable = new DataTable();
dataTable.Columns.AddRange(new DataColumn[] {
new DataColumn("IDProduct"),
new DataColumn("ProductName")
});
dataTable.Rows.Add(new object[] { "id1", "Name1" });
dataTable.Rows.Add(new object[] { "id2", "Name2" });
this.ddlProductStore.DataSource = dataTable;
}
}
</script>
<!DOCTYPE html>
<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:ComboBox
runat="server"
ValueField="IDProduct"
DisplayField="ProductName"
FieldLabel="Product"
LabelWidth="50"
Width="250">
<Store>
<ext:Store ID="ddlProductStore" runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="IDProduct" />
<ext:ModelField Name="ProductName" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>
</form>
</body>
</html>
Related
I'm sorry in advance if this seems to be a beginners question and wasted some of your time, but it does really bother me and I would really appreciate it if someone could help.
I'm simply creating a "zone" if you will, where the user inputs a word/sentence which are tasks, and then can check if the task was completed or not and/or if the word/sentence needs to be changed.
So in the end, what I need is a textbox lets say where the user inputs a specific number supposed x, and generates x times this div.
Here is the code (unfortunately I could not post pics since I do not have enough reputation..)
ASP.NET code
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="GMode.tiz.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>whatevz</title>
<link href="StyleSheet1.css" rel="stylesheet" />
<script src="../jquery-1.11.3.min.js"></script>
<script src="../functions.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div class="singleContainer">
<div class="lblPlace">
<asp:Label ID="lbl" runat="server" Text="Input Task"></asp:Label>
<asp:TextBox ID="hi" CssClass="txtBox" runat="server"></asp:TextBox>
</div>
<asp:Button ID="save" runat="server" CssClass="UniversalBtn" OnClick="btnCheck_Click" />
<asp:Button ID="cancel" runat="server" CssClass="UniversalBtn" OnClick="btnCancel_Click" />
<asp:Button ID="edit" runat="server" CssClass="UniversalBtn" />
<asp:Button ID="submit" runat="server" CssClass="BtnSubmit" OnClick="btnSubmit_Click" Text="DONE"/>
</div>
</form>
</body>
</html>
C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace GMode.tiz
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnCheck_Click(object sender, EventArgs e)
{
lbl.CssClass = "done";
}
protected void btnCancel_Click(object sender, EventArgs e)
{
lbl.CssClass = "undone";
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (hi.Text == "")
{
lbl.Text = "No Value";
}
else
{
lbl.Text = hi.Text;
}
}
}
}
So basically I want to dynamically create <div class="singleContainer"> with everything inside it x times (x defined by the user).
I'm going about this more on the fact like it's C++. When you can dynamically create an array with a specific number x.
Please tell me if you need more of the code. There are still the css and js files that I did not post.
Thank you,
Jack
I think that for this the best option is to use AngularJS, you can do something like this:
<html>
<head>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.min.js"> </script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular-resource.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular-route.min.js"></script>
<script>
var app = angular.module('app', [])
app.controller('PostsCtrl', function ($scope) {
$scope.change = function (){
$scope.listDivs = [];
for(var i=0;i<$scope.createDiv;i++) {
$scope.listDivs.push(i);
}
}
})
</script>
</head>
<body ng-app='app'>
<div ng-controller='PostsCtrl' class='container'>
<input ng-model='createDiv' ng-change="change()"/>
<ul class='list-group'>
<li ng-repeat="post in listDivs" class='list-group-item'>
<div class="singleContainer">
<div class="lblPlace">
<asp:Label ID="lbl" runat="server" Text="Input Task"> </asp:Label>
<asp:TextBox ID="hi" CssClass="txtBox" runat="server"> </asp:TextBox>
</div>
<asp:Button ID="save" runat="server" CssClass="UniversalBtn" OnClick="btnCheck_Click" />
<asp:Button ID="cancel" runat="server" CssClass="UniversalBtn" OnClick="btnCancel_Click" />
<asp:Button ID="edit" runat="server" CssClass="UniversalBtn" />
<asp:Button ID="submit" runat="server" CssClass="BtnSubmit" OnClick="btnSubmit_Click" Text="DONE"/>
</div>
</li>
</ul>
</div>
</body>
</html>
Put your div into a usercontrol (ascx file).
In your main page add a placeholder:
<asp:PlaceHolder runat="server" ID="PlaceHolder1" />
in code behind you can add your control as often as you want:
yourControl= LoadControl("~/Controls/yourControl.ascx");
PlaceHolder1.Controls.Add(yourControl);
I have displayed images in a grid view. But I don't understand how to display YouTube video in a grid-view?
Add a template column with literal control in it.
on itemdatabound fill the literal with the embed code of the YouTube video
Example:
((Literal)e.Item.FindControl("litvideo")).Text = "<iframe width=\"560\" height=\"315\" src=\"http://www.youtube.com/embed/r6BHyv6nkAs\" frameborder=\"0\" allowfullscreen></iframe>";
<asp:TemplateField ControlStyle-CssClass="Row" HeaderText="YouTube Video">
<ItemTemplate>
<asp:Label ID="lblYTVideoURL" runat="server" Text=<%# Eval("YTVideoUrl") %>></asp:Label>
</ItemTemplate>
<ControlStyle CssClass="Row"></ControlStyle>
</asp:TemplateField>
Then from the code behind:
protected void grvYoutubeVideo_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lbl = (Label)e.Row.Cells[0].Controls[1];
if (lbl.Text != "")
{
//string YTVideoURL = lbl.Text; //"http://www.youtube.com/v/AyPzM5WK8ys";
//string OBJYTVideo = "<object width=\"150\" height=\"150\">";
//OBJYTVideo += "<param name=\"movie\" value=\"" + YTVideoURL + "\"></param>";
//OBJYTVideo += "<param name=\"allowscriptaccess\" value=\"always\"></param>";
//OBJYTVideo += "<embed src=\"" + YTVideoURL + "\" type=\"application/x-shockwave-flash\"";
//OBJYTVideo += "allowscriptaccess=\"always\" width=\"100%\" height=\"100%\"></embed></object>";
//lbl.Text = OBJYTVideo;
}
}
}
try some thing like this, you can put all this in .html and open. After you will easy add this to asp.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<object width="425" height="355">
<param name="movie" value="http://www.youtube.com/v/sSe_RmPlOLM" />
<param name="wmode" value="transparent" />
<embed src="http://www.youtube.com/v/sSe_RmPlOLM" type="application/x- shockwave-flash"
wmode="transparent" width="425" height="355" />
</object>
</div>
</form>
</body>
</html>
<asp:TemplateField HeaderText="Video">
<ItemTemplate>
<iframe id="video" width="420" height="250" frameborder="0" allowfullscreen src='<%# "http://www.youtube.com/embed/" + Eval("VideoURL").ToString().Split(new string[] { "v=" }, StringSplitOptions.None)[1] %>' frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen>
</iframe>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
I seem to be having difficulty with asp:querystringparameter and asp:gridview. I have the following so far and it just returns "no data available":
<%# Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
String strGroup = Request.QueryString["group"];
switch(strGroup){
case "Clients":
ClientSource.SelectCommand = #"select client_code,
client_name from table1 where client_name = #phrase";
break;
case "Addresses":
/*different query here*/
break;
case "Matters":
/*different query here*/
break;
default:
break;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div style="font-family:Arial;">
<asp:gridview id="ClientGridView"
datasourceid="ClientSource"
emptydatatext="No data available."
runat="server">
</asp:gridview>
<asp:SqlDataSource id="ClientSource"
runat="server"
ConnectionString="connection string goes here">
<SelectParameters>
<asp:QueryStringParameter Type="String" Name="phrase" QueryStringField="phrase" />
</SelectParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
you can bind gridview dynamically in code behind also. Try to debug if your query is returning any data. Is there any specific reason to use SqlDataSource?
I am considering the feasibility of using jQuery UI themes to my ASP.NET website.
I found following issues. How do we correct them?
Internet Explorer (IE 8) --> The gridline is not visible at the bottom
(when there is no multiple pages)
Mozilla --> Gridline is not available for header
Chrome --> Working fine
Is it compatible with asp.net controls?
Can you please direct me to some examples that shows correct use of these jQuery classes with asp.net controls (without side effects)?
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.4.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.6/jquery-ui.js"></script>
<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.13/themes/sunny/jquery-ui.css"
rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
AllowPaging="True" PageSize="4">
<Columns>
<asp:BoundField DataField="ProductName" HeaderText="ProductName" ReadOnly="true"
SortExpression="ProductName" />
<asp:BoundField DataField="QuantityPerUnit" HeaderText="Qty" ReadOnly="true" SortExpression="QuantityPerUnit" />
<asp:BoundField DataField="CategoryName" HeaderText="Category" ReadOnly="true" SortExpression="CategoryName" />
</Columns>
</asp:GridView>
</div>
<br />
</form>
</body>
</html>
--Code Behind
using System;
using System.Web.UI.WebControls;
using System.Data;
public partial class MyGridTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("ProductName"), new DataColumn("QuantityPerUnit"), new DataColumn("CategoryName") });
dt.Rows.Add("Shirt", 200);
dt.Rows.Add("Football", 30);
dt.Rows.Add("Bat", 22.5);
//dt.Rows.Add("Football", 30);
//dt.Rows.Add("Bat", 22.5);
//dt.Rows.Add("Football", 30);
//dt.Rows.Add("Bat", 22.5);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
GridView1.CssClass = "ui-widget-content";
if (GridView1.Rows.Count > 0)
{
//To render header in accessible format
GridView1.UseAccessibleHeader = true;
//Add the <thead> element
GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
GridView1.HeaderRow.CssClass = "ui-widget-header";
//Add the <tfoot> element
GridView1.FooterRow.TableSection = TableRowSection.TableFooter;
if (GridView1.TopPagerRow != null)
{
GridView1.TopPagerRow.TableSection = TableRowSection.TableHeader;
}
if (GridView1.BottomPagerRow != null)
{
GridView1.BottomPagerRow.TableSection = TableRowSection.TableFooter;
}
}
}
}
Just out of interest. What happens on when you add this meta tag.
<meta http-equiv="x-ua-compatible" content="IE=8" />
.html
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="dark.css" rel="stylesheet" type="text/css" id="stylesheet" />
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<asp:Label ID="CaptionLabel" runat="server"></asp:Label>
<asp:TextBox ID="NumberTextbox" runat="server">(empty)</asp:TextBox>
<asp:Button ID="SquareButton" runat="server" Text="Square" style="background-color:Blue; color:White;" />
<asp:Label ID="ResultLabel" runat="server" Text="(empty)" CssClass="reverse"></asp:Label>
<p>
<asp:Label ID="Label1" runat="server" CssClass="footer1"
Text="Label Label Label Label LabelLabelLabel Label Label Label Label Label Label Label"></asp:Label>
</p>
<asp:RadioButton ID="radioDark" runat="server" AutoPostBack="True"
Checked="True" GroupName="grpSelectStylesheet"
oncheckedchanged="SwitchStylesheets" Text="Dark" />
<br />
<asp:RadioButton ID="radioLight" runat="server" AutoPostBack="True"
GroupName="grpSelectStylesheet" oncheckedchanged="SwitchStylesheets"
Text="Light" />
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</form>
</body>
</html>
.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void SwitchStylesheets(object sender, EventArgs e)
{
if (radioDark.Checked)
stylesheet.Href = "dark.css";
if (radioLight.Checked)
stylesheet.Href = "light.css";
}
protected void Button1_Click(object sender, EventArgs e)
{
int count=DateTime.Now.Second;
for (int i = 0; i < count; i++)
{//for
Label q = new Label();
q.ID = DateTime.Now.Second.ToString();
q.Text = DateTime.Now.Second.ToString();
string spacee = "<br />";
Label space = new Label();
space.Text = spacee;
form1.Controls.Add(q);
form1.Controls.Add(space);
}//for
}
}
When the button is clicked, it works as it should but the footer does not register the expansion of the page.
Your code is completely wrong. you cannot change the stylesheet like this for a control even if the autopostback is set to true.
UPDATE: Here's how you should do it:
1- Remove the .css reference from your page.
2- Add this method to your page:
private void UpdateStylesheet(string filepath)
{
HtmlLink newStyleSheet = new HtmlLink();
newStyleSheet.Href = filepath;
newStyleSheet.Attributes.Add("type", "text/css");
newStyleSheet.Attributes.Add("rel", "stylesheet");
Page.Header.Controls.Add(newStyleSheet);
}
3- Add this line to your page_load event:
UpdateStylesheet("dark.css");
4- Handle the SwitchStylesheets like this:
if (radioDark.Checked)
UpdateStylesheet("dark.css");
if (radioLight.Checked)
UpdateStylesheet("light.css");