有一个文本框可以搜索Gridview中的值。当显示该值时,每次单击“编辑”时,它将转到Gridview的第一个“索引行”。我想只编辑已按ID搜索的行。 例如,如果我搜索第8行中的值。它显示第8行,但是当我单击编辑时它再次转到第一行。为什么会这样?
object filename1 = @"E:\doc3.html";//path of html file
object oMissing = System.Reflection.Missing.Value;
object readOnly = false;
object oFalse = false;
Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document oDoc = new Microsoft.Office.Interop.Word.Document();
oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
oWord.Visible = false;
oDoc = oWord.Documents.Open(ref filename1, ref oMissing, ref readOnly, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
filename1 = @"E:\new.doc"; // new document path
object fileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument;
oDoc.SaveAs(ref filename1, ref fileFormat, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
oDoc.Close(ref oFalse, ref oMissing, ref oMissing);
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
return "Success";
}
答案 0 :(得分:0)
您需要修改BindGridView方法,它会解决问题。 现在,当您在任何行中搜索值并显示结果时,单击编辑时,它将保留在选定的行上。
txtSearch只是搜索文本框的ID。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridView(this.txtSearch.Text);
}
}
protected void BindGridView(string column1)
{
SqlCommand cmd = new SqlCommand("select * from table1 where (column1 like '%" + txtSearch.Text + "%')", con);
con.Open();
cmd.Parameters.AddWithValue("@column1 ", column1 );
GridView1.DataSource = cmd.ExecuteReader();
GridView1.DataBind();
con.Close();
}
protected void btnSearch_Click(object sender, EventArgs e)
{
BindGridView(this.txtSearch.Text);
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
BindGridView(this.txtSearch.Text);
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
BindGridView(this.txtSearch.Text);
}