gridview模板列中添加Button和个TextBox 要求点Button1使用 TextBox1加1
展开全部
.cs代码
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
GridView1.DataSource = 。。。
GridView1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
int index = ((GridViewRow)(((Button)sender).Parent.Parent)).RowIndex;
TextBox tbox=(TextBox)GridView1.Rows[index].Cells[0].FindControl("TextBox3");
int s = Convert.ToInt32(tbox.Text) + 1;
tbox.Text = s.ToString();
}
}
html
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
Height="148px" Width="405px">
<Columns>
<asp:TemplateField>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="TextBox3" runat="server">1</asp:TextBox>
dsfdfdsf
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Button ID="Button1" runat="server" CommandName="add" Text="Button"
onclick="Button1_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
GridView1.DataSource = 。。。
GridView1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
int index = ((GridViewRow)(((Button)sender).Parent.Parent)).RowIndex;
TextBox tbox=(TextBox)GridView1.Rows[index].Cells[0].FindControl("TextBox3");
int s = Convert.ToInt32(tbox.Text) + 1;
tbox.Text = s.ToString();
}
}
html
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
Height="148px" Width="405px">
<Columns>
<asp:TemplateField>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="TextBox3" runat="server">1</asp:TextBox>
dsfdfdsf
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Button ID="Button1" runat="server" CommandName="add" Text="Button"
onclick="Button1_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
.cs代码
public
partial
class
_Default
:
System.Web.UI.Page
{
protected
void
Page_Load(object
sender,
EventArgs
e)
{
if
(!Page.IsPostBack)
{
GridView1.DataSource
=
。
public
partial
class
_Default
:
System.Web.UI.Page
{
protected
void
Page_Load(object
sender,
EventArgs
e)
{
if
(!Page.IsPostBack)
{
GridView1.DataSource
=
。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询