【发布时间】:2021-06-15 16:06:38
【问题描述】:
我有一个Gridview,它只显示数据库表中的某些列。我的GridView 中也有一个选择按钮和删除按钮。
这是GridView的代码
<asp:GridView ID="GridViewClient" runat="server" DataKeyNames="FirstName"
OnSelectedIndexChanged="GridViewClient_SelectedIndexChanged"
OnRowDeleting="GridViewClient_RowDeleting">
<Columns>
<asp:CommandField HeaderText="Update" ShowSelectButton="True" />
<asp:CommandField HeaderText="Delete" ShowDeleteButton="True" />
</Columns>
</asp:GridView>
然后,当用户选择select 按钮时,它应该在文本框中显示整个表格。
这是select按钮的代码:
protected void GridViewClient_SelectedIndexChanged(object sender, EventArgs e)
{
EditClient.Visible = true;
GridViewRow row = GridViewClient.SelectedRow;
string constr = @"string";
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM tbl_newclient"))
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
sdr.Read();
txtFirstName.Text = sdr["FirstName"].ToString();
txtLastName.Text = sdr["LastName"].ToString();
txtContactNumber.Text = sdr["ContactNumber"].ToString();
txtEmailAddress.Text = sdr["EmailAddress"].ToString();
txtAddress.Text = sdr["Address"].ToString();
txtRestrictions.Text = sdr["Restrictions"].ToString();
txtThirdPartySupport.Text = sdr["ThirdPartySupport"].ToString();
txtBasicNotes.Text = sdr["BasicNotes"].ToString();
}
con.Close();
}
}
Update.Visible = true;
}
texboxes 在页面加载时隐藏,仅在select 上可见
现在发生的情况是,当我单击任意行上的 select 按钮时,GridView 的第一行会显示在文本框中?
我不确定我在这里做错了什么?
谢谢
【问题讨论】: