想要在表格的每一行中显示两个额外的元素,请说 - '更新'并且'删除'链接标签

时间:2017-05-03 04:03:30

标签: c# mysql asp.net .net

这是我从数据库中读取表的asp代码。但是在显示表格时,我想在每一行中有额外的元素进行更新和删除。怎么样?

MySqlDataAdapter da = new MySqlDataAdapter("select StudentId, StudentName from tblStudent", con);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();

帮我提出建议。

1 个答案:

答案 0 :(得分:0)

除了学生ID和姓名外,请尝试以下显示编辑和删除:

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowSorting="True"
                AllowPaging="True" OnRowEditing="GridView1_RowEditing" OnRowCancelingEdit="GridView1_RowCancelingEdit"
                    OnRowDataBound="GridView1_RowDataBound" OnRowUpdating="GridView1_RowUpdating" OnPageIndexChanging="GridView1_PageIndexChanging"
                    OnRowDeleting="GridView1_OnRowDeleting" OnRowCreated="GridView1_RowCreated" 
                    OnSelectedIndexChanged="GridView1_OnSelectedIndexChanged" GridLines="Horizontal">
                        <Columns>
                            <asp:CommandField ShowEditButton="True" ButtonType="Button" ItemStyle-BorderWidth="1px" HeaderStyle-BorderWidth="1px"
                                HeaderStyle-CssClass="dgrid" ItemStyle-CssClass="dgrid" />
                            <asp:CommandField ShowDeleteButton="True" ButtonType="Button" ItemStyle-BorderWidth="1px" HeaderStyle-BorderWidth="1px"
                                HeaderStyle-CssClass="dgrid" ItemStyle-CssClass="dgrid" />


                           <asp:BoundField DataField="StudentId" HeaderText="Student Id" />
                            </asp:BoundField>
                            <asp:BoundField DataField="StudentName" HeaderText="Student Name" />
                            </asp:BoundField>
                   </Columns>

                    </asp:GridView>