footer中绑定了控件,可是如何捕捉控件的事件?

jlqidan 2003-09-01 09:14:09
protected void Pic_DG_Items_Created(object sender,System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Footer)
{
int i = 0;
LinkButton Addhl = new LinkButton();
Addhl.Text = "添加";
Addhl.ID = "AddRecord";
LinkButton Cancelhl = new LinkButton();
Cancelhl.Text = "取消";
Cancelhl.ID = "CancelRecord";

foreach(TableCell tc in e.Item.Cells)
{
if(i == 0)
{
e.Item.Cells[0].Controls.Add(Addhl);
}
else if(i == 1)
{
e.Item.Cells[1].Controls.Add(Cancelhl);
}
else
{
TextBox tb = new TextBox();
tb.ID = "tb" + i;
tc.Controls.Add(tb);
}
i = i+1;
}

}
}

上面是我在footer中绑定了两个命令和控件的函数,但现在的问题是我如何在程序中识别我点击的命令是确定还是取消呀?
...全文
75 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jpyc 2003-09-14
  • 打赏
  • 举报
回复
事件要在footer中写
xrll 2003-09-13
  • 打赏
  • 举报
回复
public void LkClick(Object sender, EventArgs e)
{
String arg = ((LinkButton)sender).CommandArgument;
switch(arg)
{
case ("add1"):
......
break;
case ("add2"):
......
break;
default:
break;
}

要在两个linkbutton中加入事件:
Addhl.Click += new System.EventHandler(this.LkClick);
Addh2.Click += new System.EventHandler(this.LkClick);
Addhl.CommandArgument = "add1";
Addh2.CommandArgument = "add2";


coolmars 2003-09-02
  • 打赏
  • 举报
回复
up
guoyan19811021 2003-09-01
  • 打赏
  • 举报
回复
可以设置CommandArgument的值
早事件里:
select case Sender.CommandArgument
case""
end select
guoyan19811021 2003-09-01
  • 打赏
  • 举报
回复
If e.CommandName = "Insert" Then

Dim t1 As TextBox = e.Item.FindControl("textbox2")
Dim t2 As TextBox = e.Item.FindControl("textbox4")
Dim t3 As TextBox = e.Item.FindControl("TextBox6")
Dim a As Label = e.Item.FindControl("label1")
a.Text = "SSSS"

cnn.Open()
Dim cmd As New OleDbCommand("insert into log (usercode,pwd,username) values('" & t1.Text & "','" & t2.Text & "','" & t3.Text & "' )", cnn)
cmd.ExecuteNonQuery()
cnn.Close()
BindGrid()
Session("1") = t1.Text
Session("2") = t2.Text
Session("3") = t3.Text
Dim item As DataGridItem
For Each item In DataGrid1.Controls(0).Controls

If (item.ItemType = ListItemType.Footer) Then

Dim txt1 As TextBox
Dim txt2 As TextBox
Dim txt3 As TextBox

txt1 = item.FindControl("textbox2")
txt1.Width = Unit.Pixel(60)
txt1.TextMode = TextBoxMode.SingleLine
If Not Session("1") Is Nothing Then
txt1.Text = Session("1")
End If
txt2 = item.FindControl("textbox4")
txt2.Width = Unit.Pixel(60)
txt2.TextMode = TextBoxMode.SingleLine
If Not Session("2") Is Nothing Then
txt2.Text = Session("2")
End If
txt3 = item.FindControl("textbox6")
txt3.Width = Unit.Pixel(60)
txt3.TextMode = TextBoxMode.SingleLine
If Not Session("3") Is Nothing Then
txt3.Text = Session("3")
End If


End If
Next
End If

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧