![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
<%@ Page Theme="Default" Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="EditIndividualCell.aspx.cs" Inherits="Ajax学习.EditIndividualCell" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cph" runat="server">
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"
onitemdatabound="Repeater1_ItemDataBound"
ondatabinding="Repeater1_DataBinding" onitemcreated="Repeater1_ItemCreated">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text = '<% # Eval("TM") %>' TextMode="MultiLine">'></asp:TextBox><asp:TextBox ID="TextBox2" runat="server" Text = '<% # Eval("YHM") %>' TextMode="MultiLine">'></asp:TextBox><br />
<asp:DropDownList ID = "ddl" runat="server" DataTextField="YHM" DataValueField="YHM" ></asp:DropDownList><br />
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:QingShiConnectionString %>"
DeleteCommand="DELETE FROM ML WHERE (SXH = @sxh)"
InsertCommand="INSERT INTO ML(SXH, TM, XGRQ, IS_SELECTED, YHM) VALUES (@sxh, @tm, @xgrq, @IS_SELECTED)"
SelectCommand="SELECT TOP (10) SXH, TM, XGRQ, IS_SELECTED, YHM FROM ML"
UpdateCommand="UPDATE ML SET TM = @tm, XGRQ = @xgrq, IS_SELECTED = @IS_SELECTED, YHM = @YHM WHERE (SXH = @sxh)">
<DeleteParameters>
<asp:Parameter Name="sxh" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="tm" />
<asp:Parameter Name="xgrq" />
<asp:Parameter Name="IS_SELECTED" />
<asp:Parameter Name="YHM" />
<asp:Parameter Name="sxh" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="sxh" />
<asp:Parameter Name="tm" />
<asp:Parameter Name="xgrq" />
<asp:Parameter Name="IS_SELECTED" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="sqlds" runat="server" ConnectionString="<%$ ConnectionStrings:QingShiConnectionString %>" SelectCommand="Select distinct yhm from ml" ></asp:SqlDataSource>
</asp:Content>
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace Ajax学习
{
public partial class EditIndividualCell : System.Web.UI.Page
{
SqlDataReader dr;
DataSet ds;
SqlDataAdapter da;
protected void Page_Load(object sender, EventArgs e)
{
getdata();
}
private DataSet getdata(){
SqlConnection conn;
SqlCommand cmd;
conn = new SqlConnection("Data Source=.;Initial Catalog=QingShi;Integrated Security=True");
cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "select distinct YHM from ML";
conn.Open();
da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
dr = cmd.ExecuteReader();
return ds;
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
DropDownList ddl = (DropDownList)e.Item.FindControl("ddl");
ddl.DataSource = ds;
ddl.DataTextField = "YHM";
ddl.DataValueField = "YHM";
TextBox t = (TextBox)e.Item.FindControl("TextBox2");
ddl.DataBind();
DataRowView drv = (DataRowView)e.Item.DataItem;
ddl.Items.FindByValue(drv["YHM"].ToString()).Selected = true;
}
protected void Repeater1_DataBinding(object sender, EventArgs e)
{
}
protected void Repeater1_ItemCreated(object sender, RepeaterItemEventArgs e)
{
}
}
}