我的一个DataGrid绑定了关于书的一些信息 中有一个模版列 里面有一个表格 ,里面显示了书的名字 我是
<TR>
<TD> 书名:<%# DataBinder.Eval(Container, "DataItem.bookName") %>
</TD>
</TR>
这样显示书名的。里面还有一个button 我把它的CommandName设成了com1,用于我在点击的时候可以写button的click事件 但是我在写事件的时候怎么才能知道是哪一行的button被点了??还有我怎么才能在点击事件里取到书的名字??
解决马上结贴!!!!我用的03
<TR>
<TD> 书名:<%# DataBinder.Eval(Container, "DataItem.bookName") %>
</TD>
</TR>
这样显示书名的。里面还有一个button 我把它的CommandName设成了com1,用于我在点击的时候可以写button的click事件 但是我在写事件的时候怎么才能知道是哪一行的button被点了??还有我怎么才能在点击事件里取到书的名字??
解决马上结贴!!!!我用的03
解决方案 »
- asp.net 调用FlashPrinter.exe 把所有可打印的文件转换成swf文件 运行没有效果
- 关于使用数据集进行模糊查询
- 请问 如何将Oracle的及时数据交换进SqlServer
- 我要买个asp.net 空间,大家帮忙测试一下速度好吗
- 下拉列表框联动, 急
- 请救一个gridview控件HyperLinkField根据不同条件显示不同文字连接
- 急求一个正则表达式
- asp与asp.net如何共享cookie
- 关于Windows server 2003 ADSI的问题!用asp.net开发
- 关于Gridview中enable delete, update的功能
- 请教中文编码方式。
- 快崩溃了,哪位好心人帮忙啊
{ switch(e.CommandName)
{ case "com1": // Call the method to sort the list.
Sort_List((String)e.CommandArgument);
break; case "com2": // Display a message for the Submit button being clicked.
Message.Text = "You clicked the Submit button"; // Test whether the command argument is an empty string ("").
if((String)e.CommandArgument == "")
{
// End the message.
Message.Text += ".";
}
else
{
// Display an error message for the command argument.
Message.Text += ", however the command argument is not recogized.";
}
break; default: // The command name is not recognized. Display an error message.
Message.Text = "Command name not recogized.";
break; }
模版的btclick 时间是通过datagrid等 控件的 CommandBtn_Click事件 统一执行的
怎么区分是那个bt的事件呢
switch(e.CommandName)
CommandName 这个名字就是 你的模版的bt按钮的标记 后台可以根据CommandName 名字 区分是那个 bt按钮 的事件
你在模版的bt按钮 右击 就能出来选择 菜单内 找到 他的设置
bt的事件 就需要
switch(e.Item.事件名称)
//如果 某个事件名称 为com1
case "com1":
.... 执行你的代码
}
BorderColor="black"
BorderWidth="1"
CellPadding="3"
OnItemCommand="ItemsGrid_Command"
AutoGenerateColumns="false"
runat="server"> <HeaderStyle BackColor="#aaaadd">
</HeaderStyle>
<Columns> <asp:EditCommandColumn
EditText="Edit"
CancelText="Cancel"
UpdateText="Update"
HeaderText="Edit item"> <ItemStyle Wrap="False">
</ItemStyle> <HeaderStyle Wrap="False">
</HeaderStyle> </asp:EditCommandColumn> <asp:ButtonColumn
HeaderText="Delete item"
ButtonType="LinkButton"
Text="Delete"
CommandName="Delete"/>
........
</Columns>
</asp:DataGrid>void ItemsGrid_Command(Object sender, DataGridCommandEventArgs e)
{ switch(((LinkButton)e.CommandSource).CommandName)
{ case "Delete":
DeleteItem(e);
break; // Add other cases here, if there are multiple ButtonColumns in
// the DataGrid control. default:
// Do nothing.
break; } }