 |
|
ASP.NET & Dropdownlist in GridView??? (By VB.NET , C#) |
|
 |
|
|
 |
 |
|
การ add event เข้าไปใน control ครับ
อันนี้เป็นตัวอย่าง เช็คบอค ที่อยู่บนสุดเมื่อติกแล้ว เชคบอคลูกๆจะถูกเลือกทั้งหมดครับ
Code (C#)
protected void GrvJob_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
CheckBox chbAll = (CheckBox)e.Row.FindControl("chbAll");
chbAll.CheckedChanged += new EventHandler(chbAll_CheckedChanged);
// ณ จุดนี้ผมว่าสามารถ bind ข้อมูลลงใน ดรอปดาว ตามที่คุณต้องการได้
}
}
protected void chbAll_CheckedChanged(object sender, EventArgs e)
{
CheckBox cb1 = (CheckBox)sender;
CheckBox cb2;
foreach (GridViewRow gv in GrvJob.Rows)
{
cb2 = (CheckBox)gv.Cells[0].FindControl("ChkSeqNo");
cb2.Checked = cb1.Checked;
}
}
|
 |
 |
 |
 |
Date :
2009-08-20 10:29:26 |
By :
besttooo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณคุณเบสมากครับ เดี๋ยวผมลองดู
|
 |
 |
 |
 |
Date :
2009-08-20 13:10:18 |
By :
nutkit |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าอยู่ ฟุตเตอร์ เปลี่ยน บรรทัดนี้ if (e.Row.RowType == DataControlRowType.Header)
จาก .Header เป็นตำแหน่งนั้นๆที่ต้องการด้วย
|
 |
 |
 |
 |
Date :
2009-08-20 15:46:09 |
By :
besttooo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พอดีในกริดมี dropdownlist 2 ตัว ลองทำตามคุณเบสแล้วใช้ได้ครับแต่มีปัญหาดังนี้
ณ ตอนที่Row create ผมก็สั่งbind ข้อมูลแบบคุณเบส โดยเพิ่มevent onselectindexcahnage ไปด้วย
เมื่อมันchange ให้มันbind dropdownlist ตัวสอง ซึ่งก็ได้ผล ข้อมูลในddl2 ถูกต้องแล้ว
แต่ปัญหามันเกิดว่า เมื่อผมเลือกอะไรก็ตามที่ddl2 มันก็จะไมมีผล มันจะไปอยู่ที่itemแรกเสมอ
ผมเลยลองใส่ event onselectindexchange ของ ddl2 ด้วย ปรากฎว่า มันไม่เข้าevent เวลาเลือกครับ
คือเหมือนมันไบน์ข้อมูลได้ แต่มันไม่active อะไรแล้วชีวิตนี้
มีครเคยทำไหมครับ
|
 |
 |
 |
 |
Date :
2009-08-26 15:07:10 |
By :
nutkit |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มีใครเคยทำไหมครับ T T
|
 |
 |
 |
 |
Date :
2009-08-27 14:56:17 |
By :
nutkit |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หวัดดีครับ s.b.y14แสดงความเป็นเพื่อน 2 ครับ
   
|
 |
 |
 |
 |
Date :
2010-06-07 09:20:09 |
By :
goo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หวัดดีครับs.b.y.14แสดงความรัก 3ครับ
|
 |
 |
 |
 |
Date :
2010-06-07 09:25:38 |
By :
โกเด้น |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มีแต่ที่เป็น VB.NET น่ะครับ
Code (VB.NET)
<%@ Page Language="VB" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
Dim objConn As OleDbConnection
Dim objCmd As OleDbCommand
Dim strSQL As String
Sub Page_Load(sender As Object, e As EventArgs)
Dim strConnString As String
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& _
Server.MapPath("database/mydatabase2.mdb")&";"
objConn = New OleDbConnection(strConnString)
objConn.Open()
IF Not Page.IsPostBack() Then
BindData()
End IF
End Sub
Sub BindData()
strSQL = "SELECT * FROM customer"
Dim dtReader As OleDbDataReader
objCmd = New OleDbCommand(strSQL, objConn)
dtReader = objCmd.ExecuteReader()
'*** BindData to GridView ***'
myGridView.DataSource = dtReader
myGridView.DataBind()
dtReader.Close()
dtReader = Nothing
End Sub
Sub Page_UnLoad()
objConn.Close()
objConn = Nothing
End Sub
Function DataTableCountryCode() As DataTable
Dim strConnString As String
Dim dtAdapter As OleDbDataAdapter
Dim dt As New DataTable
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& _
Server.MapPath("database/mydatabase2.mdb")&";"
objConn = New OleDbConnection(strConnString)
objConn.Open()
Dim strSQL As String
strSQL = "SELECT * FROM country"
dtAdapter = New OleDbDataAdapter(strSQL, objConn)
dtAdapter.Fill(dt)
dtAdapter = Nothing
Return dt
End Function
Sub modEditCommand(sender As Object, e As GridViewEditEventArgs)
myGridView.EditIndex = e.NewEditIndex
myGridView.ShowFooter = False
BindData()
End Sub
Sub modCancelCommand(sender As Object, e As GridViewCancelEditEventArgs)
myGridView.EditIndex = -1
myGridView.ShowFooter = True
BindData()
End Sub
Sub modDeleteCommand(sender As Object, e As GridViewDeleteEventArgs)
strSQL = "DELETE FROM customer WHERE CustomerID = '" & myGridView.DataKeys.Item(e.RowIndex).Value & "'"
objCmd = New OleDbCommand(strSQL, objConn)
objCmd.ExecuteNonQuery()
myGridView.EditIndex = -1
BindData()
End Sub
Sub myGridView_RowCommand(source As Object, e As GridViewCommandEventArgs)
If e.CommandName = "Add" Then
'*** CustomerID ***'
Dim txtCustomerID As TextBox = CType(myGridView.FooterRow.FindControl("txtAddCustomerID"), TextBox)
'*** Name ***'
Dim txtName As TextBox = CType(myGridView.FooterRow.FindControl("txtAddName"), TextBox)
'*** Email ***'
Dim txtEmail As TextBox = CType(myGridView.FooterRow.FindControl("txtAddEmail"), TextBox)
'*** CountryCode ***'
Dim ddlCountryCode As DropDownList = CType(myGridView.FooterRow.FindControl("ddlAddCountryCode"), DropDownList)
'*** Budget ***'
Dim txtBudget As TextBox = CType(myGridView.FooterRow.FindControl("txtAddBudget"), TextBox)
'*** Used ***'
Dim txtUsed As TextBox = CType(myGridView.FooterRow.FindControl("txtAddUsed"), TextBox)
strSQL = "INSERT INTO customer (CustomerID,Name,Email,CountryCode,Budget,Used) " & _
" VALUES ('" & txtCustomerID.Text & "','" & txtName.Text & "','" & txtEmail.Text & "' " & _
" ,'" & ddlCountryCode.SelectedItem.Value & "','" & txtBudget.Text & "','" & txtUsed.Text & "') "
objCmd = New OleDbCommand(strSQL, objConn)
objCmd.ExecuteNonQuery()
BindData()
End If
End Sub
Sub myGridView_RowDataBound(source As Object, e As GridViewRowEventArgs)
'*** Footer ***'
IF e.Row.RowType = DataControlRowType.Footer Then
'*** CountryCode ***'
Dim ddlCountryCode As DropDownList = CType(e.Row.FindControl("ddlAddCountryCode"), DropDownList)
IF Not IsNothing(ddlCountryCode) Then
With ddlCountryCode
.DataSource = DataTableCountryCode
.DataTextField = "CountryName"
.DataValueField = "CountryCode"
.DataBind()
End With
End IF
End IF
'*** Edit ***'
IF e.Row.RowType = DataControlRowType.DataRow Then
'*** CustomerID ***'
Dim txtCustomerID As TextBox = CType(e.Row.FindControl("txtEditCustomerID"), TextBox)
IF Not IsNothing(txtCustomerID) Then
txtCustomerID.Text = e.Row.DataItem("CustomerID")
End IF
'*** Name ***'
Dim txtName As TextBox = CType(e.Row.FindControl("txtEditName"), TextBox)
IF Not IsNothing(txtName) Then
txtName.Text = e.Row.DataItem("Name")
End IF
'*** Email ***'
Dim txtEmail As TextBox = CType(e.Row.FindControl("txtEditEmail"), TextBox)
IF Not IsNothing(txtEmail) Then
txtEmail.Text = e.Row.DataItem("Email")
End IF
'*** CountryCode ***'
Dim ddlCountryCode As DropDownList = CType(e.Row.FindControl("ddlEditCountryCode"), DropDownList)
IF Not IsNothing(ddlCountryCode) Then
With ddlCountryCode
.DataSource = DataTableCountryCode
.DataTextField = "CountryName"
.DataValueField = "CountryCode"
.DataBind()
End With
ddlCountryCode.SelectedIndex = ddlCountryCode.Items.IndexOf(ddlCountryCode.Items.FindByValue(e.Row.DataItem("CountryCode")))
End IF
'*** Budget ***'
Dim txtBudget As TextBox = CType(e.Row.FindControl("txtEditBudget"), TextBox)
IF Not IsNothing(txtBudget) Then
txtBudget.Text = e.Row.DataItem("Budget")
End IF
'*** Used ***'
Dim txtUsed As TextBox = CType(e.Row.FindControl("txtEditUsed"), TextBox)
IF Not IsNothing(txtUsed) Then
txtUsed.Text = e.Row.DataItem("Used")
End IF
End IF
End Sub
Sub modUpdateCommand(s As Object, e As GridViewUpdateEventArgs)
'*** CustomerID ***'
Dim txtCustomerID As TextBox = CType(myGridView.Rows(e.RowIndex).FindControl("txtEditCustomerID"), TextBox)
'*** Name ***'
Dim txtName As TextBox = CType(myGridView.Rows(e.RowIndex).FindControl("txtEditName"), TextBox)
'*** Email ***'
Dim txtEmail As TextBox = CType(myGridView.Rows(e.RowIndex).FindControl("txtEditEmail"), TextBox)
'*** CountryCode ***'
Dim ddlCountryCode As DropDownList = CType(myGridView.Rows(e.RowIndex).FindControl("ddlEditCountryCode"), DropDownList)
'*** Budget ***'
Dim txtBudget As TextBox = CType(myGridView.Rows(e.RowIndex).FindControl("txtEditBudget"), TextBox)
'*** Used ***'
Dim txtUsed As TextBox = CType(myGridView.Rows(e.RowIndex).FindControl("txtEditUsed"), TextBox)
strSQL = "UPDATE customer SET CustomerID = '" & txtCustomerID.Text & "' " & _
" ,Name = '" & txtName.Text & "' " & _
" ,Email = '" & txtEmail.Text & "' " & _
" ,CountryCode = '" & ddlCountryCode.SelectedItem.Value & "' " & _
" ,Budget = '" & txtBudget.Text & "' " & _
" ,Used = '" & txtUsed.Text & "' " & _
" WHERE CustomerID = '" & myGridView.DataKeys.Item(e.RowIndex).Value & "'"
objCmd = New OleDbCommand(strSQL, objConn)
objCmd.ExecuteNonQuery()
myGridView.EditIndex = -1
myGridView.ShowFooter = True
BindData()
End Sub
</script>
<html>
<head>
<title>ThaiCreate.Com ASP.NET - GridView</title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView id="myGridView" runat="server" AutoGenerateColumns="False"
ShowFooter="True"
DataKeyNames="CustomerID"
OnRowEditing="modEditCommand"
OnRowCancelingEdit="modCancelCommand"
OnRowDeleting="modDeleteCommand"
OnRowUpdating="modUpdateCommand"
OnRowCommand="myGridView_RowCommand"
OnRowDataBound="myGridView_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="CustomerID">
<ItemTemplate>
<asp:Label id="lblCustomerID" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.CustomerID") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtEditCustomerID" size="5" runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAddCustomerID" size="5" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label id="lblName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Name") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtEditName" size="10" runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAddName" size="10" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email">
<ItemTemplate>
<asp:Label id="lblEmail" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Email") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtEditEmail" size="20" runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAddEmail" size="20" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CountryCode">
<ItemTemplate>
<asp:Label id="lblCountryCode" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.CountryCode") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="ddlEditCountryCode" runat="server"></asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList id="ddlAddCountryCode" runat="server"></asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Budget">
<ItemTemplate>
<asp:Label id="lblBudget" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Budget") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtEditBudget" size="6" runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAddBudget" size="6" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Used">
<ItemTemplate>
<asp:Label id="lblUsed" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Used") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtEditUsed" size="6" runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAddUsed" size="6" runat="server"></asp:TextBox>
<asp:Button id="btnAdd" runat="server" Text="Add" CommandName="Add"></asp:Button>
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" CancelText="Cancel" DeleteText="Delete" EditText="Edit" UpdateText="Update" HeaderText="Modify" />
<asp:CommandField ShowDeleteButton="True" HeaderText="Delete" />
</Columns>
</asp:GridView>
</form>
</body>
</html>
|
 |
 |
 |
 |
Date :
2010-09-10 15:16:12 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แปลงเป็น C# ให้เลยครับ
Code (C#)
<%@ Page Language="C#" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
OleDbConnection objConn;
OleDbCommand objCmd;
String strSQL;
void Page_Load(object sender,EventArgs e)
{
String strConnString;
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
Server.MapPath("database/mydatabase.mdb") + ";";
objConn = new OleDbConnection(strConnString);
objConn.Open();
if(!Page.IsPostBack)
{
BindData();
}
}
void BindData()
{
String strSQL;
strSQL = "SELECT * FROM customer";
OleDbDataReader dtReader;
objCmd = new OleDbCommand(strSQL, objConn);
dtReader = objCmd.ExecuteReader();
//*** BindData to GridView ***//
myGridView.DataSource = dtReader;
myGridView.DataBind();
dtReader.Close();
dtReader = null;
objConn.Close();
objConn = null;
}
public DataTable DataTableCountryCode()
{
String strConnString = null;
OleDbDataAdapter dtAdapter = OleDbDataAdapter;
DataTable dt = new DataTable();
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("database/mydatabase.mdb") + ";";
objConn = new OleDbConnection(strConnString);
objConn.Open();
string strSQL = null;
strSQL = "SELECT * FROM country";
dtAdapter = new OleDbDataAdapter(strSQL, objConn);
dtAdapter.Fill(dt);
dtAdapter = null;
return dt;
}
void modEditCommand(Object sender, GridViewEditEventArgs e)
{
myGridView.EditIndex = e.NewEditIndex;
myGridView.ShowFooter = false;
BindData();
}
void modCancelCommand(Object sender, GridViewCancelEditEventArgs e)
{
myGridView.EditIndex = -1;
myGridView.ShowFooter = true;
BindData();
}
void modDeleteCommand(Object sender, GridViewDeleteEventArgs e)
{
strSQL = "DELETE FROM customer WHERE CustomerID = '" + myGridView.DataKeys[e.RowIndex].Value + "'";
objCmd = new OleDbCommand(strSQL, objConn);
objCmd.ExecuteNonQuery();
myGridView.EditIndex = -1;
BindData();
}
void myGridView_RowCommand(Object source , GridViewCommandEventArgs e)
{
if (e.CommandName == "Add")
{
//*** CustomerID ***//
TextBox txtCustomerID = (TextBox)myGridView.FooterRow.FindControl("txtAddCustomerID");
//*** Name ***//
TextBox txtName = (TextBox)myGridView.FooterRow.FindControl("txtAddName");
//*** Email ***//
TextBox txtEmail = (TextBox)myGridView.FooterRow.FindControl("txtAddEmail");
//*** CountryCode ***//
DropDownList ddlCountryCode = (DropDownList)myGridView.FooterRow.FindControl("ddlAddCountryCode");
//*** Budget ***//
TextBox txtBudget = (TextBox)myGridView.FooterRow.FindControl("txtAddBudget");
//*** Used ***//
TextBox txtUsed = (TextBox)myGridView.FooterRow.FindControl("txtAddUsed");
strSQL = "INSERT INTO customer (CustomerID,Name,Email,CountryCode,Budget,Used) " +
" VALUES ('" + txtCustomerID.Text + "','" + txtName.Text + "','" + txtEmail.Text + "' " +
" ,'" + ddlCountryCode.SelectedItem.Value + "','" + txtBudget.Text + "','" + txtUsed.Text + "') ";
objCmd = new OleDbCommand(strSQL, objConn);
objCmd.ExecuteNonQuery();
BindData();
}
}
void myGridView_RowDataBound(Object source , GridViewRowEventArgs e)
{
//*** Footer ***'
if (e.Row.RowType == DataControlRowType.Footer) {
//*** CountryCode ***'
DropDownList ddlCountryCode = (DropDownList)e.Row.FindControl("ddlAddCountryCode");
if ((ddlCountryCode != null)) {
ddlCountryCode.DataSource = (DataTable)DataTableCountryCode();
ddlCountryCode.DataTextField = "CountryName";
ddlCountryCode.DataValueField = "CountryCode";
ddlCountryCode.DataBind();
}
}
//*** Edit ***'
if (e.Row.RowType == DataControlRowType.DataRow) {
//*** CustomerID ***'
TextBox txtCustomerID = (TextBox)e.Row.FindControl("txtEditCustomerID");
if ((txtCustomerID != null)) {
txtCustomerID.Text = (string)DataBinder.Eval(e.Row.DataItem, "CustomerID");
}
//*** Name ***'
TextBox txtName = (TextBox)e.Row.FindControl("txtEditName");
if ((txtName != null)) {
txtName.Text = (string)DataBinder.Eval(e.Row.DataItem, "Name");
}
//*** Email ***'
TextBox txtEmail = (TextBox)e.Row.FindControl("txtEditEmail");
if ((txtEmail != null)) {
txtEmail.Text = (string)DataBinder.Eval(e.Row.DataItem, "Email");
}
//*** CountryCode ***'
DropDownList ddlCountryCode = (DropDownList)e.Row.FindControl("ddlEditCountryCode");
if ((ddlCountryCode != null)) {
ddlCountryCode.DataSource = (DataTable)DataTableCountryCode();
ddlCountryCode.DataTextField = "CountryName";
ddlCountryCode.DataValueField = "CountryCode";
ddlCountryCode.DataBind();
ddlCountryCode.SelectedIndex = ddlCountryCode.Items.IndexOf(ddlCountryCode.Items.FindByValue((string)DataBinder.Eval(e.Row.DataItem, "CountryCode")));
}
//*** Budget ***'
TextBox txtBudget = (TextBox)e.Row.FindControl("txtEditBudget");
if ((txtBudget != null)) {
txtBudget.Text = DataBinder.Eval(e.Row.DataItem, "Budget").ToString();
}
//*** Used ***'
TextBox txtUsed = (TextBox)e.Row.FindControl("txtEditUsed");
if ((txtUsed != null)) {
txtUsed.Text =DataBinder.Eval(e.Row.DataItem, "Used").ToString();
}
}
}
void modUpdateCommand(Object sender,GridViewUpdateEventArgs e)
{
//*** CustomerID ***//
TextBox txtCustomerID = (TextBox)myGridView.Rows[e.RowIndex].FindControl("txtEditCustomerID");
//*** Name ***//
TextBox txtName = (TextBox)myGridView.Rows[e.RowIndex].FindControl("txtEditName");
//*** Email ***//
TextBox txtEmail = (TextBox)myGridView.Rows[e.RowIndex].FindControl("txtEditEmail");
//*** CountryCode ***//
DropDownList ddlCountryCode = (DropDownList)myGridView.Rows[e.RowIndex].FindControl("ddlEditCountryCode");
//*** Budget ***//
TextBox txtBudget = (TextBox)myGridView.Rows[e.RowIndex].FindControl("txtEditBudget");
//*** Used ***//
TextBox txtUsed = (TextBox)myGridView.Rows[e.RowIndex].FindControl("txtEditUsed");
strSQL = "UPDATE customer SET CustomerID = '" + txtCustomerID.Text + "' " +
" ,Name = '" + txtName.Text + "' " +
" ,Email = '" + txtEmail.Text + "' " +
" ,CountryCode = '" + ddlCountryCode.SelectedItem.Value + "' " +
" ,Budget = '" + txtBudget.Text + "' " +
" ,Used = '" + txtUsed.Text + "' " +
" WHERE CustomerID = '" + myGridView.DataKeys[e.RowIndex].Value + "'";
objCmd = new OleDbCommand(strSQL, objConn);
objCmd.ExecuteNonQuery();
myGridView.EditIndex = -1;
myGridView.ShowFooter = true;
BindData();
}
</script>
<html>
<head>
<title>ThaiCreate.Com ASP.NET - GridView</title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView id="myGridView" runat="server" AutoGenerateColumns="False"
ShowFooter="True"
DataKeyNames="CustomerID"
OnRowEditing="modEditCommand"
OnRowCancelingEdit="modCancelCommand"
OnRowDeleting="modDeleteCommand"
OnRowUpdating="modUpdateCommand"
OnRowCommand="myGridView_RowCommand"
OnRowDataBound="myGridView_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="CustomerID">
<ItemTemplate>
<asp:Label id="lblCustomerID" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.CustomerID") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtEditCustomerID" size="5" runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAddCustomerID" size="5" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label id="lblName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Name") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtEditName" size="10" runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAddName" size="10" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email">
<ItemTemplate>
<asp:Label id="lblEmail" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Email") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtEditEmail" size="20" runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAddEmail" size="20" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CountryCode">
<ItemTemplate>
<asp:Label id="lblCountryCode" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.CountryCode") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="ddlEditCountryCode" runat="server"></asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList id="ddlAddCountryCode" runat="server"></asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Budget">
<ItemTemplate>
<asp:Label id="lblBudget" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Budget") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtEditBudget" size="6" runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAddBudget" size="6" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Used">
<ItemTemplate>
<asp:Label id="lblUsed" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Used") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtEditUsed" size="6" runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAddUsed" size="6" runat="server"></asp:TextBox>
<asp:Button id="btnAdd" runat="server" Text="Add" CommandName="Add"></asp:Button>
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" CancelText="Cancel" DeleteText="Delete" EditText="Edit" UpdateText="Update" HeaderText="Modify" />
<asp:CommandField ShowDeleteButton="True" HeaderText="Delete" />
</Columns>
</asp:GridView>
</form>
</body>
</html>
|
 |
 |
 |
 |
Date :
2010-09-10 15:47:28 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|