编辑GridView里面如何获取InputText控件的值 20

之前用textbox获取数据的方法,protectedvoidGridView1_RowUpdating(objectsender,GridViewUpdateEvent... 之前用textbox获取数据的方法,
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string cell1 = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
……
}
inputtext如何获取
<input type="text" class="inline laydate-icon" id="start" value="<%#Eval("stime","{0:yyyy-MM-dd}")%>" style="width:120px;"/>
展开
 我来答
在晴天的雨伞
2016-06-01 · TA获得超过6869个赞
知道大有可为答主
回答量:5761
采纳率:86%
帮助的人:1177万
展开全部
如果是主键,你可以到GridView里面去设定成如:
DataKeyNames="id"
<asp:GridView ID="gdvUserInfo" runat="server" AutoGenerateColumns="False" DataKeyNames="id">

获取的时候:
/// <summary>
/// 删除信息事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gdvUserInfo_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string id =gdvUserInfo.DataKeys[e.RowIndex].Value.ToString();
if (info.DeleteUserInfoById(id) > 0)
{
this.lblMessage.Text = "删除成功!";
LoadInfo();
}
else
{
this.lblMessage.Text = "删除失败!";
LoadInfo();
}
}

/// <summary>
/// 编辑事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gdvUserInfo_RowEditing(object sender, GridViewEditEventArgs e)
{
gdvUserInfo.EditIndex = e.NewEditIndex;
LoadInfo();
}

/// <summary>
/// 取消编辑事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gdvUserInfo_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
gdvUserInfo.EditIndex = -1;
LoadInfo();
}

/// <summary>
/// 更新事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gdvUserInfo_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string userId = gdvUserInfo.DataKeys[e.RowIndex].Value.ToString();
TextBox txtUserId = (TextBox)gdvUserInfo.Rows[e.RowIndex].Cells[0].FindControl("txtUserId");
TextBox txtUserName = (TextBox)gdvUserInfo.Rows[e.RowIndex].Cells[0].FindControl("txtUserName");
TextBox txtPassWord = (TextBox)gdvUserInfo.Rows[e.RowIndex].Cells[0].FindControl("txtPassWord");
if (txtUserName != null && txtPassWord != null)
{
try
{
UserInfo user = info.GetUserInfoById(userId);
user.UserName = txtUserName.Text.ToString();
user.Password = txtPassWord.Text.ToString();
if (info.ModifyUserInfo(user) > 0)
{
this.lblMessage.Text = "修改成功!";
gdvUserInfo.EditIndex = -1;
LoadInfo();
}
else
{
this.lblMessage.Text = "修改失败!";
gdvUserInfo.EditIndex = -1;
LoadInfo();
}
}
catch (Exception)
{

this.lblMessage.Text = "修改失败!";
gdvUserInfo.EditIndex = -1;
LoadInfo();
}
}
}

/// <summary>
///
/// 光棒事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gdvUserInfo_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i < gdvUserInfo.Rows.Count; i++)
{
if (gdvUserInfo.Rows[i].RowType == DataControlRowType.DataRow)
{
gdvUserInfo.Rows[i].Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#9cf'");
gdvUserInfo.Rows[i].Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式