|
|
|
ปัญหาสร้าง combobox หลายอันไม่ได้.............................!? |
|
|
|
|
|
|
|
ขอรายละเอียด ว่าจะเอาไปทำอะไร...
|
|
|
|
|
Date :
2011-03-19 22:12:46 |
By :
koungkung |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
กรอกข้อมูลแล้ว add ลง db ครับ
ตรง combobox ดึงข้อมูลมาให้เลือก
|
|
|
|
|
Date :
2011-03-19 22:32:37 |
By :
hamzter |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
รู้สึกเจ้า ajax combobox จะมีปัญหาตอนทำเป็น dynamic control ค่ะ
ลองหลายวิธีละ ไม่ได้เหมือนกัน แต่ถ้าใช้ gridview >> template coloumn จะทำได้ค่ะ
|
|
|
|
|
Date :
2011-03-23 13:41:09 |
By :
สาวเอ๋อ เอ๋อเหรอ เอ๋อมากมาย |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ถ้าใช้ gridview จะประมาณนี้ค่ะ ไม่ได้ลง code ที่มันใช้งานเท่าไหร่นะคะ
Code (ASP)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="HtmlGrid.aspx.cs" Inherits="Pages_StandDardControl_Grid_HtmlGrid" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!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>
</head>
<body>
<form id="form1" runat="server">
<div style="margin: 0 auto">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:GridView ID="GridViewData" runat="server" AutoGenerateColumns="false" ShowFooter="true" ShowHeader ="true" >
<Columns>
<asp:TemplateField>
<HeaderStyle HorizontalAlign="Center" Width="80px" Font-Size="10px" />
<HeaderTemplate>
Order
</HeaderTemplate>
<ItemStyle HorizontalAlign="Center" Width="80px" Font-Size="10px" />
<ItemTemplate>
<asp:Label ID="LabelCounter" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderStyle HorizontalAlign="Center" Width="210px" Font-Size="10px" />
<HeaderTemplate>
Item# <span>
<asp:TextBox ID="TextBoxTotalRowAppearence" runat="server" Width="40px">
</asp:TextBox></span> <span>
<asp:Button ID="Button1" runat="server" Text="Go" /></span>
</HeaderTemplate>
<ItemStyle HorizontalAlign="Center" Width="210px" Font-Size="10px" />
<ItemTemplate>
<asp:ComboBox ID="ComboBoxDataItem" runat="server" Width="200px">
</asp:ComboBox>
</ItemTemplate>
<FooterStyle HorizontalAlign="Center" Width="210px" Font-Size="10px" Font-Bold="true" />
<FooterTemplate>
Grand total:
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderStyle HorizontalAlign="Center" Width="100px" Font-Size="10px" />
<HeaderTemplate>
@Price
</HeaderTemplate>
<ItemStyle HorizontalAlign="Center" Width="100px" Font-Size="10px" />
<ItemTemplate>
<asp:TextBox ID="TextBoxPricePerUnit" runat="server" Width="95%">
</asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderStyle HorizontalAlign="Center" Width="100px" Font-Size="10px" />
<HeaderTemplate>
Qty
</HeaderTemplate>
<ItemStyle HorizontalAlign="Center" Width="100px" Font-Size="10px" />
<ItemTemplate>
<asp:TextBox ID="TextBoxQuantity" runat="server" Width="95%">
</asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderStyle HorizontalAlign="Center" Width="100px" Font-Size="10px" />
<HeaderTemplate>
Total
</HeaderTemplate>
<ItemStyle HorizontalAlign="Center" Width="100px" Font-Size="10px" />
<ItemTemplate>
<asp:Label ID="LabelTotal" runat="server" ForeColor="RoyalBlue" Text="-"></asp:Label>
</ItemTemplate>
<FooterStyle HorizontalAlign="Center" Width="100px" Font-Size="10px" Font-Bold="true" />
<FooterTemplate>
<asp:Label ID="LabelGrandTotal" runat="server" ForeColor="Blue" Text="-"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderStyle HorizontalAlign="Center" Width="300px" Font-Size="10px" />
<HeaderTemplate>
Comment
</HeaderTemplate>
<ItemStyle HorizontalAlign="Left" Width="300px" Font-Size="10px" />
<ItemTemplate>
<asp:TextBox ID="TextBoxComment" runat="server" Width="95%">
</asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Pages_StandDardControl_Grid_HtmlGrid : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
InitDataSource(5);
}
//LiteralWriteTable(4);
}
protected override void OnInit(EventArgs e)
{
GridViewData.RowDataBound += new GridViewRowEventHandler(this.RowDataBound);
base.OnInit(e);
}
private void InitDataSource(int varDataRow)
{
SimpleData[] DataSource = new SimpleData[varDataRow];
GridViewData.DataSource = DataSource;
GridViewData.DataBind();
}
private void RowDataBound(object Sender, GridViewRowEventArgs e)
{
string[] SimpleList = new string[] { "Earth", "Moon", "Star" };
if (e.Row.RowType == DataControlRowType.DataRow)
{
AjaxControlToolkit.ComboBox myComboBox
= e.Row.FindControl("ComboBoxDataItem") as AjaxControlToolkit.ComboBox;
if (myComboBox != null)
{
myComboBox.DataSource = SimpleList;
myComboBox.DataBind();
}
Label lbCounter = e.Row.FindControl("LabelCounter") as Label ;
if (lbCounter != null)
{
lbCounter.Text = (e.Row.RowIndex + 1).ToString("00");
}
}
}
private void LiteralWriteTable(int varTotalRow)
{
if (varTotalRow <= 0) return;
this.WriteLiteralDataLn("<div style=\"background-color : pink ; width : 960px ; height : auto ; margin : 0 auto\">");
this.WriteLiteralDataLn(" <table cellpadding =\"2\" cellspacing =\"0\" border=\"01\" width=\"960px\"> ");
this.WriteLiteralDataLn(" <colgroup>");
this.WriteLiteralDataLn(" <col width=\"80px\" align=\"center\"");
this.WriteLiteralDataLn(" <col width=\"250px\" align=\"left\"");
this.WriteLiteralDataLn(" <col width=\"100px\" align=\"right\"");
this.WriteLiteralDataLn(" <col width=\"100px\" align=\"right\"");
this.WriteLiteralDataLn(" <col width=\"120px\" align=\"right\"");
this.WriteLiteralDataLn(" <col width=\"310px\" align=\"left\"");
this.WriteLiteralDataLn(" </colgroup>");
this.WriteLiteralDataLn(" <tbody>");
for (int myRow = 0; myRow < varTotalRow; myRow++)
{
this.WriteLiteralDataLn(" <tr>");
for (int myColumn = 0; myColumn < 6; myColumn++)
{
switch (myColumn)
{
case 0:
this.WriteLiteralTableCellData(12, (myRow + 1).ToString("00"));
break;
case 1:
AjaxControlToolkit.DropDownExtender myDDownExtender = new AjaxControlToolkit.DropDownExtender();
TextBox myTextBox = new TextBox();
this.WriteLiteralTableCellContent(12, myTextBox);
myDDownExtender.TargetControlID = myTextBox.ID;
this.Form.Controls.Add(myDDownExtender);
break;
default:
this.WriteLiteralTableCellData(12, (myColumn + 1).ToString("00"));
break;
;
}
}
this.WriteLiteralDataLn(" </tr>");
}
this.WriteLiteralDataLn(" </tbody>");
this.WriteLiteralDataLn(" </table>");
this.WriteLiteralDataLn("</div>");
}
}
public static class EnhanceExtension
{
public static void WriteLiteralData(this Page Thing, string varData)
{
Thing.Form.Controls.Add(new LiteralControl(varData));
}
public static void WriteLiteralDataLn(this Page Thing, string varData)
{
Thing.Form.Controls.Add(new LiteralControl(varData + "\n"));
}
public static void WriteLiteralTableCellData(this Page Thing, string varData)
{
Thing.Form.Controls.Add(new LiteralControl("<td>"));
Thing.Form.Controls.Add(new LiteralControl(varData));
Thing.Form.Controls.Add(new LiteralControl("</td>\n"));
}
public static void WriteLiteralTableCellData(this Page Thing, int varIndent, string varData)
{
string indentStr = string.Empty.PadLeft(varIndent);
Thing.Form.Controls.Add(new LiteralControl(indentStr + "<td>"));
Thing.Form.Controls.Add(new LiteralControl(varData));
Thing.Form.Controls.Add(new LiteralControl("</td>\n"));
}
public static void WriteLiteralTableCellContent<T>(this Page Thing, int varIndent, T varContent)
where T : System.Web.UI.WebControls.WebControl
{
string indentStr = string.Empty.PadLeft(varIndent);
Thing.Form.Controls.Add(new LiteralControl(indentStr + "<td>"));
Thing.Form.Controls.Add(varContent);
Thing.Form.Controls.Add(new LiteralControl("</td>\n"));
}
}
public class SimpleData
{
public string Name { get; set; }
public double Price { get; set; }
public SimpleData() { }
public SimpleData(string varName, double varPrice)
{
this.Name = varName; this.Price = varPrice;
}
}
ตัว LiteralWriteTable มัน error นะคะไม่ต้องไปสนใจมัน
|
|
|
|
|
Date :
2011-03-23 16:54:53 |
By :
สาวเอ๋อ เอ๋อเหรอ เอ๋อมากมาย |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ถ้าใช้ Gridview คุณก็ทำการ find Control ทีละตัว แล้ว Bindding ที่ละตัวครับ...
|
|
|
|
|
Date :
2011-03-25 20:24:51 |
By :
koungkung |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|