gridview使用命令名称 [英] gridview using command name
本文介绍了gridview使用命令名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过使用命令名称来开发网格视图编辑,删除,更新...但是在我之间的e.NewEditIndex和e.RowIndex中有以下代码中的错误。(在此我不想要使用这个Row_Editing和Row_Deleting事件)plz帮助我.......
(我给你一些重要的设计代码和开发代码)
I want develop grid view edit,delete,update by using "Command Name"...but in between i got Errors at "e.NewEditIndex" and "e.RowIndex" in following code.(in this i dont want to use this Row_Editing and Row_Deleting events) plz help me.......
(i give u some important design code and developing code)
gridview.aspx:
<pre lang="text"></pre>
<asp:GridView ID="gridemp" runat="server" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None" OnRowCommand="gridemp_RowCommand" OnRowEditing="gridemp_RowCommand">
/*here i wrote all binding code*/
<asp:gridview>
gridview.aspx.cs
protected void gridemp_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "add")
{
gridemp.FooterRow.Visible = true;
lbl.Text = "";
}
else if (e.CommandName == "edit")
{
GridViewRow row = e.NewEditIndex;
lbl.Text = "";
}
else if (e.CommandName == "delete")
{
string cs = "Server=WASEEM\\SQLEXPRESS;database=malik;Trusted_Connection=yes;";
SqlConnection con = new SqlConnection(cs);
con.Open();
GridViewRow row = gridemp.Rows[e.Rowindex];
/* remaining code*/
}
}
plz查看此代码(.cs)在这个我们如何传递e.NewEditIndex和e.RowIndex
所以这里可以启用任何事件..plz使用命令名称编写程序
修改代码块[/ edit]
推荐答案
尝试使用以下内容获取索引和行of gridview。
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = ContactsGridView.Rows [index];
Try using following to get index and rows of gridview.
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = ContactsGridView.Rows[index];
这篇关于gridview使用命令名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文