/// <summary>
/// 生成事件时激发
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void DVClientInfo_RowCommand(object sender, GridViewCommandEventArgs e)
{
int strProjectId = ?;
if (e.CommandName == "redact")//编辑
{
}
else if (e.CommandName == "forbid")//禁用
{
bool temp = centaline.Pro.ClassLibrary.Property.CProject.UpStatusF(strProjectId);
}
else if (e.CommandName == "comeback")//恢复
{
bool temp = centaline.Pro.ClassLibrary.Property.CProject.UpStatusR(strProjectId);
}
}
页面代码:
<asp:GridView ID="DVClientInfo" runat="server" onrowdatabound="DVClientInfo_RowDataBound" onrowcommand="DVClientInfo_RowCommand">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<input id="Checkbox2" type="checkbox" runat="server" /><label>全选</label>
</HeaderTemplate>
</asp:TemplateField>
<asp:BoundField Visible="False" DataField="ProjectId">
</asp:BoundField>
<asp:BoundField DataField="PropertyName" HeaderText="项目名称" ></asp:BoundField>
<asp:BoundField DataField="PropertyCode" HeaderText="项目编号" ></asp:BoundField>
<asp:BoundField DataField="PropertyDept" HeaderText="隶属部门" ></asp:BoundField>
<asp:BoundField DataField="Status" HeaderText="状态" ></asp:BoundField>
<asp:TemplateField HeaderText="操作">
<ItemTemplate>
<asp:LinkButton ID="lbtn_redact" runat="server" CommandName="redact" >编辑</asp:LinkButton>
<asp:LinkButton ID="lbtn_forbid" runat="server" CommandName="forbid" >禁用</asp:LinkButton>
<asp:LinkButton ID="lbtn_comeback" runat="server" CommandName="comeback" >恢复</asp:LinkButton>
</ItemTemplate>
<Itemstyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
</asp:GridView>效果如上!我要获得 int strProjectId = ?; 的值 请教各位高手大哥帮帮忙!
/// 生成事件时激发
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void DVClientInfo_RowCommand(object sender, GridViewCommandEventArgs e)
{
int strProjectId = ?;
if (e.CommandName == "redact")//编辑
{
}
else if (e.CommandName == "forbid")//禁用
{
bool temp = centaline.Pro.ClassLibrary.Property.CProject.UpStatusF(strProjectId);
}
else if (e.CommandName == "comeback")//恢复
{
bool temp = centaline.Pro.ClassLibrary.Property.CProject.UpStatusR(strProjectId);
}
}
页面代码:
<asp:GridView ID="DVClientInfo" runat="server" onrowdatabound="DVClientInfo_RowDataBound" onrowcommand="DVClientInfo_RowCommand">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<input id="Checkbox2" type="checkbox" runat="server" /><label>全选</label>
</HeaderTemplate>
</asp:TemplateField>
<asp:BoundField Visible="False" DataField="ProjectId">
</asp:BoundField>
<asp:BoundField DataField="PropertyName" HeaderText="项目名称" ></asp:BoundField>
<asp:BoundField DataField="PropertyCode" HeaderText="项目编号" ></asp:BoundField>
<asp:BoundField DataField="PropertyDept" HeaderText="隶属部门" ></asp:BoundField>
<asp:BoundField DataField="Status" HeaderText="状态" ></asp:BoundField>
<asp:TemplateField HeaderText="操作">
<ItemTemplate>
<asp:LinkButton ID="lbtn_redact" runat="server" CommandName="redact" >编辑</asp:LinkButton>
<asp:LinkButton ID="lbtn_forbid" runat="server" CommandName="forbid" >禁用</asp:LinkButton>
<asp:LinkButton ID="lbtn_comeback" runat="server" CommandName="comeback" >恢复</asp:LinkButton>
</ItemTemplate>
<Itemstyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
</asp:GridView>效果如上!我要获得 int strProjectId = ?; 的值 请教各位高手大哥帮帮忙!
int index = gvrow.RowIndex;
string tNumber =GridView_projectTask.DataKeys[index].
Values["strProjectId "].ToString();
/// <summary>
/// 生成事件时激发
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void DVClientInfo_RowCommand(object sender, GridViewCommandEventArgs e)
{
int strProjectId = if (e.CommandName == "redact")//编辑
{ }
else if (e.CommandName == "forbid")//禁用
{
bool temp = centaline.Pro.ClassLibrary.Property.CProject.UpStatusF(strProjectId);
if (temp)
{
Bind();
}
}
else if (e.CommandName == "comeback")//恢复
{
bool temp = centaline.Pro.ClassLibrary.Property.CProject.UpStatusR(strProjectId);
if (temp)
{
Bind();
}
}
}
/// <summary>
/// 生成事件时激发
/// </summary>
/// <param name="source"></param>
/// <param name="e"></param>
protected void grdbank_ItemCommand(object source, DataGridCommandEventArgs e)
{
int strPropertyId = Convert.ToInt32(e.Item.Cells[0].Text); if (e.CommandName == "lb1")
{
ProjectRedact.Visible = true; this.Label1.Text = e.Item.Cells[1].Text.ToString().Trim();
this.Label2.Text = e.Item.Cells[2].Text.ToString().Trim();
this.TextBox6.Text = e.Item.Cells[3].Text.ToString().Trim();
this.TextBox7.Text = e.Item.Cells[4].Text.ToString().Trim();
this.TextBox8.Text = e.Item.Cells[5].Text.ToString().Trim();
this.TextBox9.Text = e.Item.Cells[6].Text.ToString().Trim();
}
else if (e.CommandName == "lb2")
{
bool temp = EM_Project.ClassLibrary.CUser.UpPropertyF(strPropertyId); if (temp)
{
Bind();
}
}
else if (e.CommandName == "lb3")
{
bool temp = EM_Project.ClassLibrary.CUser.UpPropertyR(strPropertyId); if (temp)
{
Bind();
}
}
}能不能像DataGrid里面一样
用这样int strPropertyId = Convert.ToInt32(e.Item.Cells[0].Text);的语句代替?
因为对GridView不太熟悉!
GridViewRow gvrow = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
int index = gvrow.RowIndex;
string tNumber =DVClientInfo.rows[index][2].tostring()
this.gvData.DataKeyNames = new string[] { "ID" };gvData为你的控件名称,然后在后台
grdbank_ItemCommand时间里面:
long id = long.Paese(this.gvData.DataKeys[e.RowIndex].Value)
看看能获取到不!
错误 37 无法将带 [] 的索引应用于“System.Web.UI.WebControls.GridViewRow”类型的表达式
少写了个 “.”
DVClientInfo.Rows [index ].Cells [2].tostring
在gridview中设置datakey 添加你要找的列
GridViewRow gvrow = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
int index = gvrow.RowIndex;
string tNumber =GridView_projectTask.DataKeys[index].
Values["这是字段名"].ToString();方法二:
GridViewRow gvrow = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
int index = gvrow.RowIndex;
string id=DVClientInfo.Rows [index ].Cells [2].ToString();够清楚了吧,我常用的就这2种