怎样用C#写一个asp.net的web自定义控件

2024-12-16 22:52:10
推荐回答(3个)
回答1:

别激发RowEditing了,手写吧。
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>









using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class WebUserControl : System.Web.UI.UserControl
{
protected void Page_Load( object sender , EventArgs e )
{
if ( !IsPostBack )
{
List ss = new List();
for ( int i = 0 ; i < 10 ; i++ )
{
ss.Add( i.ToString() );
}
gv.DataSource = ss;
gv.DataBind();
}
}
protected void TextBox1_TextChanged( object sender , EventArgs e )
{
string str = ( (TextBox)sender ).Text;
}
protected void gv_RowDataBound( object sender , GridViewRowEventArgs e )
{
if ( e.Row.RowType != DataControlRowType.DataRow )
{
return;
}
TextBox tb = (TextBox)e.Row.Cells[0].FindControl( "tb" );
tb.Text = e.Row.DataItem.ToString();
}
}
//如果是多行显示,可以再往里放一个隐藏域,用来记录数据的唯一约束键。

回答2:







回答3:

在开发工具里设置属性,应该是这样的吧,你去试着琢磨一下。