add combobox items with different text and value
September 3, 2009
We can do it with DataBinding a combobox with DataSet or DataTable object. And we can also do it with customer objects. There are two ways to do this.
Here is the customer object:
public class cbxItem
{
private string _Text;
private long _Value;
public string Text{get{return _Text;}}
public long Value{get{return _Value;}}
public cbxItem(string theText, long theValue)
{
_Text = theText;
_Value = theValue;
}
}
Way 1: using DataBinding with customer objects as DataSet
……
ArrayList cbxObjects= new ArrayList();
while(theDataReader.Read())
{
cbxObjects.Add (new cbxItem (theDataReader.GetString(1),theDataReader.GetInt32 (0)));
}
this.ComboBox1.DataSource = Authors;
this.ComboBox1.DisplayMember =”Text”;
this.ComboBox1.ValueMember = “Value”;
……
Way 2: directly using ComboBox.items.Add(obj) with customer objects:
……
while(theDataReader.Read())
{
ComboBox1.Items.Add (new cbxItem (theDataReader.GetString(1),theDataReader.GetInt32 (0)));
}
……
GridView’s border setting doesn’t work in IE!
June 6, 2009
I only tried IE7.0, but it did donot work well if you have this setting in your GridView:
<asp:GridView ID=”GridView1″ runat=”server” BorderColor=”red” BoderStyle=”Solid” BorderWidth=”1px” RowStyle-BorderColor=”blue” RowStyle-BorderStyle=”Solid” RowStyle-BorderWidth=”1px” ……>
<……/>
But using css works:
1. create css class
<style type=”text/css”>
table.GridViewCss td,th
{
height:25px;
color:#333333;
border:solid 1px #6A8CA5;
border-collapse: collapse;
}
table.GridViewCss
{
height:25px;
color:#333333;
border:solid 1px #6A8CA5;
border-collapse: collapse;
}
</style>
2. use it
<asp:GridView ID=”GridView1″ runat=”server” CssClass=”GridViewCss” ……>
<……/>
use OnClientClick of LinkButton with bound data
June 6, 2009
I have some linkButtons in GridView, and I want to call a client-side javascript method with bound data when user click on it.
<asp:LinkButton OnClientClick=’<%# “alert(‘” + Eval(“something”) + “‘)” %>’ ……>
unfortunately, it doesn’t work.
<asp:LinkButton OnClientClick=’<%# Eval(“something”, “alert(‘{0}’)” %>’ ……>
it doesn’t work too.
Only works for me when use codebehind:
protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lnkbtn = (LinkButton)e.Row.FindControl("lnkbtn");
string st= DataBinder.Eval(e.Row.DataItem, "something").ToString();
lnkbtn.Attributes.Add("onclick", string.Format("alert('{0}')", st));
}
}
Create XMLHttpRequest object
April 13, 2009
var xmlHttp = false;
function getXmlHttpRequestObject() {
// check for native XMLHttpRequest object
if(window.XMLHttpRequest && !(window.ActiveXObject)) {
try {
xmlHttp = new XMLHttpRequest();
}
catch(e) {
xmlHttp = false;
}
}
// check for IE/Windows ActiveX version
else if(window.ActiveXObject) {
try {
xmlHttp = new ActiveXObject(“Msxml2.XMLHTTP”);
}
catch(e) {
try {
xmlHttp = new ActiveXObject(“Microsoft.XMLHTTP”);
}
catch(e) {
xmlHttp = false;
}
}
}
}
The XMLHttpRequest object can make requests only to the same domain as the currently loaded page. This security policy is also known as the “same origin” policy.
