在不同的地方查找Textbox和主键:
1.在FSLGridView1_RowDataBound中查找模板列中的TextBox
1
protected
void
FSLGridView1_RowDataBound(
object
sender, GridViewRowEventArgs e)
2
{
3
//
判断当前行是否是数据行
4
if
(e.Row.RowType
==
DataControlRowType.DataRow)
5
{
6
TextBox txt1
=
(TextBox)e.Row.FindControl(
"
txtDBFix
"
);
7
txt1.Text
=
e.Row.Cells[
1
].Text;
8
}
9
}
上例:将第0列的值赋到txtDbFix的文本框列中,另外获取主键ID:int ID = this.GridView1.DataKeys[e.Row.RowIndex].Value;
运用:把GridView中某列的值赋到模板列中的TextBox中去。
2.在FSLGridView1_RowCommand中查找模板列中的TextBox和主键
前台:
<asp:TemplateField HeaderText="关闭提醒">
<ItemTemplate>
<fsl:FSLButton runat="server" ID="FSLButClose" SkinID="fslButton" Text="关闭提醒" CommandName="updateremind"
CommandArgument='<%# DataBinder.Eval(Container,"RowIndex") %>' />
</ItemTemplate>
</asp:TemplateField>
后台:
代码
protected
void
FSLGridView3_RowCommand(
object
sender, GridViewCommandEventArgs e)
{
if
((
string
)e.CommandName
==
"
updateremind
"
)
{
RemindInfo remindInfo
=
new
RemindInfo();
int
index
=
Convert.ToInt32((
string
)e.CommandArgument);
remindInfo.updateByRmguid(FSLGridView3.DataKeys[index].Value.ToString());
ClientScript.RegisterStartupScript(GetType(),
""
,
"
<script language='javascript'>alert('关闭成功!');window.location.href='MyJobTable.aspx';</script>
"
);
this
.FSLGridView3.DataBind();
}
}
运用:GridView中每行修改数据
3.在普通的按钮中查找模板列中的TextBox和主键
1
protected
void
FSLButDbUpdate_Click(
object
sender, EventArgs e)
2
{
3
foreach
(GridViewRow row
in
FSLGridView1.Rows)
4
{
5
if
(row.RowType
==
DataControlRowType.DataRow)
6
{
7
if
(row.RowState
==
DataControlRowState.Normal
||
row.RowState
==
DataControlRowState.Alternate)
8
{
9
System.Web.UI.WebControls.TextBox TextBox1
=
(System.Web.UI.WebControls.TextBox)row.FindControl(
"
txtDBFix
"
);
10
System.Web.UI.WebControls.TextBox TextBox2
=
(System.Web.UI.WebControls.TextBox)row.FindControl(
"
txtTotalDBFix
"
);
11
12
if
(
string
.IsNullOrEmpty(
this
.ddlDay.SelectedValue))
13
{
14
if
(
string
.IsNullOrEmpty(
this
.ddlMonth.SelectedValue))
15
{
16
tblTPCCSummeryUtitiy.UpdateDBYear(FSLGridView1.DataKeys[row.RowIndex].Value.ToString(), TextBox1.Text,
1
, TextBox2.Text,
1
);
17
}
18
else
19
{
20
tblTPCCSummeryUtitiy.UpdateDBMonth(FSLGridView1.DataKeys[row.RowIndex].Value.ToString(), TextBox1.Text,
1
, TextBox2.Text,
1
);
21
}
22
}
23
else
24
{
25
tblTPCCSummeryUtitiy.UpdateDBDay(FSLGridView1.DataKeys[row.RowIndex].Value.ToString(), TextBox1.Text,
1
, TextBox2.Text,
1
);
26
}
27
28
}
29
}
30
}
31
32
this
.FSLGridView1.DataBind();
33
}