我在aspx中使用gridview,我有两个页面注册和details.aspx一旦注册完成它应该转到details.aspx中的详细信息页面我在那个GV中保留了一个gridview我应该使用行命令事件作为一个按钮应该使用编辑按钮显示学生的所有结果,作为我使用项目模板的所有学生的最后一列。但是在行命令事件中,如果用户单击编辑,我不知道要编写的函数,它应该使用用户 ID 进入编辑页面,ID 应该是中午可编辑模式,其他字段可以编辑。
详细信息.aspx
<asp:GridView ID="GridView3" runat="server" CellPadding="3" ForeColor="#333333" GridLines="None" AutoGenerateColumns="false" OnRowCommand="GridView3_RowCommand" OnSelectedIndexChanged="GridView3_SelectedIndexChanged">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="UserName" HeaderText="UserName" ReadOnly="True"/>
<asp:BoundField DataField="Password" HeaderText="Password" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:BoundField DataField="EMail" HeaderText="Emaid-ID" />
<asp:BoundField DataField="PhoneNo" HeaderText="Phone Number" />
<asp:BoundField DataField="Location" HeaderText="Location" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:Button ID="btnedit" runat="server" Text="Edit" CommandName="Edit" CommandArgument="UserName"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
</div>
</form>
详细信息.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
string connection2 = System.Web.Configuration.WebConfigurationManager.ConnectionStrings ["connection1"].ConnectionString;
SqlConnection con = new SqlConnection(connection2);
con.Open();
SqlCommand cmd = new SqlCommand("select * from User_Information", con);
SqlDataReader rdr = cmd.ExecuteReader();
GridView3.DataSource = rdr;
GridView3.DataBind();
con.Close();
}
protected void GridView3_RowCommand(object sender, GridViewCommandEventArgs e)
{
}
protected void GridView3_SelectedIndexChanged(object sender, EventArgs e)
{
}
}