编辑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;"/> 展开
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;"/> 展开
1个回答
展开全部
如果是主键,你可以到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");
}
}
}
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");
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询