GridView ASP.NET c # data from the same table

2

I have the following table in SQL with the following fields (id, name, day, week, active). id the primary key of the integer type; name nvchar day week nvchar; active bit; and I have the following data in the table 1; Joseph; Monday 1; 2; Joseph; Wednesday; 1; I want to display this data in a gridview of type;

Tipo colunas: TEXTBOX || Checkbox || Checkbox|| Checkbox||...
Nome colunas:  nome || segunda || terça || quarta ||...
Dados:        jose  || x       ||        || x ||...

When editing, remove the record from that day, and if it does not exist create a new record for that day. I'm doing this in web forms application. I hope you understand what I mean.

    
asked by anonymous 21.03.2014 / 19:50

2 answers

2
        <%@ Page Language="C#" AutoEventWireup="false" CodeFile="Template.aspx.cs" Inherits="Template" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Explorando o GridView - Visual C#</title>
</head>
<body>
    <form id="form1" runat="server">
        <br />
        <table width="60%" align="center" bgcolor="#cccccc" cellpadding="1" cellspacing="0">            
            <tr>
                <td>
                    <table width="100%" align="center" bgcolor="#ffffff">
                        <tr>
                            <td align="center">
                                <br />
                                <font face="arial" size="2">
                                    <b>Explorando o GridView - Visual C#</b><br />
                                    Por Felipe Albuquerque<br />
                                    <a href="mailto:[email protected]">[email protected]</a><br />
                                    <a href="felipealbuquerq.blogspot.com" target="_blank">http://http://felipealbuquerq.blogspot.com</a>
                                </font>
                            </td>
                        </tr>
                        <tr><td><br /><hr size="1" noshade /><br /></td></tr>
                        <tr>
                            <td>
                                <font face="arial" size="2">
                                    <table width="100%" align="center">
                                        <tr>
                                            <td><b>Utilizando Template Columns</b></td>
                                            <td align="right"><a href="Default.aspx"><< Indice</a></td>
                                        </tr>
                                        <tr><td colspan="2">&nbsp;</td></tr>
                                        <tr>
                                            <td colspan="2">
                                                <br />
                                                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnString %>"
                                                    SelectCommand="SELECT [*] FROM [Agenda]"></asp:SqlDataSource>
                                                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
                                                    <Columns>
                                                        <asp:BoundField DataField="Nome" HeaderText="Nome" SortExpression="Nome" />
                                                        <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:CheckBox ID="SegundaFeira" runat="server" />
                                </ItemTemplate>
                            </asp:TemplateField>
                                                        <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:CheckBox ID="TercaFeira" runat="server" />
                                </ItemTemplate>
                            </asp:TemplateField>
                                                        <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:CheckBox ID="QuartaFeira" runat="server" />
                                </ItemTemplate>
                            </asp:TemplateField>
                                                        <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:CheckBox ID="QuintaFeira" runat="server" />
                                </ItemTemplate>
                            </asp:TemplateField>
                                                        <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:CheckBox ID="SextaFeira" runat="server" />
                                </ItemTemplate>
                            </asp:TemplateField>
                                                    </Columns>
                                                </asp:GridView>
                                            </td>
                                        </tr>
                                    </table>
                                </font>
                            </td>
                        </tr>
                        <tr><td><hr size="1" noshade /></td></tr>
                        <tr><td align="right"><a href="http://beta.asp.net"><img border="0" src="Images/ASPNET.gif" /></a>&nbsp;</td></tr>
                    </table>
                </td>
            </tr>
        </table>
    </form>
</body>
</html>
    
27.03.2014 / 03:08
2

If it is possible? Yes, of course. But if you really want to get help with your case, you need to provide more specific details as suggested by @tchicotti.

With what you can understand with your question, you can only say yes, and in the view you need to fill in the checkboxes according to the data returned by your query, and, according to the action of the user you will either need to either update a record or insert a new record.

    
22.03.2014 / 15:05