0
我有一個在asp.net中的gridview,我在其中插入數據。當我插入重複值時,它會顯示項目重複。現在我需要在項目重複提醒消息後顯示光標將重點放在行值包含重複的項目。如果我的數據表已經包含代碼C1,那麼我再次鍵入c1進行插入,然後光標將聚焦在gridview中包含c1的行。這裏是我的代碼重點設置重複的行數據,同時輸入重複值
protected void Button15_Click(object sender, EventArgs e)
{
Control control = null;
if (GridView1.FooterRow != null)
{
control = GridView1.FooterRow;
}
else
{
control = GridView1.Controls[0].Controls[0];
}
string Code = (control.FindControl("txtcode") as TextBox).Text;
string txtno= (control.FindControl("txtno") as TextBox).Text;
using (SqlConnection con = new SqlConnection("Data Source=XXXXXX;Initial Catalog=XXXXXX;User ID=XXXX;Password=XXXXXX"))
{
using (SqlCommand cmd = new SqlCommand())
{
DataTable dt = new DataTable();
SqlDataAdapter da1;
da1 = new SqlDataAdapter("select code from tbltmp where code='" + Code + "' ", con);
da1.Fill(dt);
if (dt.Rows.Count > 0)
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(),
"alertMessage",
"alert('Item Repeated');", true);
(control.FindControl("txtcode") as TextBox).Focus();
}
else
{
(control.FindControl("txtno") as TextBox).Focus();
}
}
}
}