Diskuze: Select Datagrid ASP.NET

C# .NET .NET (C# a Visual Basic) Select Datagrid ASP.NET American English version English version

Avatar
Maros2470
Člen
Avatar
Maros2470:

Zdravím všechny. Potřeboval bych poradit jak napsat, aby po stisku SelectButon u DataGrid, došlo k přepnutí na další stránku, kde bych chtěl zobrazovat podrobnosti. DataGrid mám napsán takto:

<asp:GridView ID="gvData" runat="server" AutoGenerateColumns="False" DataKeyNames="ApplianceId" DataSourceID="SqlDataSource1" AllowSorting="True" OnSelectedIndexChanged="gvData_SelectedIndexChanged">
                   <EmptyDataTemplate>
                       <div style="padding: 10px">
                           No DataFound!
                       </div>
                   </EmptyDataTemplate>
                   <Columns>
                       <asp:CommandField ShowSelectButton="True" />
                       <asp:BoundField HeaderText="Spotřebič Id" DataField="ApplianceId" ReadOnly="True" SortExpression="ApplianceId" />
                       <asp:BoundField HeaderText="Název spotřebiče" DataField="Name" SortExpression="Name" />
                       <asp:BoundField HeaderText="Inventární číslo" DataField="InvertoryNumber" SortExpression="InvertoryNumber" />
                       <asp:BoundField HeaderText="Výrobní číslo" DataField="SerialNumber" SortExpression="SerialNumber" />
                       <asp:BoundField HeaderText="Revizní interval (měs.)" DataField="RevisionInterval" SortExpression="RevisionInterval" />
                       <asp:BoundField HeaderText="Skupina" DataField="Group" SortExpression="Group" />
                       <asp:BoundField HeaderText="Třída" DataField="ProtectionClass" SortExpression="ProtectionClass" />
                       <asp:BoundField HeaderText="Datum revize" DataField="MeasDate" SortExpression="MeasDate" />
                       <asp:BoundField HeaderText="Status" DataField="MeasGlobalStatus" SortExpression="MeasGlobalStatus" />
                   </Columns>

               </asp:GridView>
 
Odpovědět 14.9.2014 17:47
Avatar
Odpovídá na Maros2470
Michal Štěpánek:

Toto se řeší přidáním sloupce do DGV, kde bude hyperlinkfield s odkazem na stránku podrobností a pomocí querystringu se předává parametr toho konkrétního řádku (v tvém případě asi ID toho spotřebiče).

Nahoru Odpovědět 14.9.2014 17:54
Nikdy neříkej nahlas, že to nejde. Vždycky se totiž najde blbec, který to neví a udělá to...
Avatar
Odpovídá na Michal Štěpánek
Michal Štěpánek:

například takto:

<asp:HyperLinkField DataNavigateUrlFields="ApplianceId" DataNavigateUrlFormatString="StrankaDetailu.aspx?id={0}" NavigateUrl="StrankaDetailu.aspx" Text="Detail" />
Nahoru Odpovědět 14.9.2014 18:01
Nikdy neříkej nahlas, že to nejde. Vždycky se totiž najde blbec, který to neví a udělá to...
Avatar
Maros2470
Člen
Avatar
Odpovídá na Michal Štěpánek
Maros2470:

Díky. S ASP.NET začínám a zatím se celkem daří, jen občas zůstanu na něčem viset.

 
Nahoru Odpovědět 14.9.2014 18:19
Avatar
Maros2470
Člen
Avatar
Odpovídá na Maros2470
Maros2470:

Ještě jeden dotaz. Detail chci načíst do FormView. Data načítám stejně jako u DataGrid z DataSource. Když nastavuji dotaz tak Select je jasný, ale z čeho mám načíst při setavování dotazu, Where ApplianceID, které bylo předáno z předchozí stránky. V rozevíracím seznamu je několik možností, ale nevím, kterou a jak použít.

Editováno 14.9.2014 18:43
 
Nahoru Odpovědět 14.9.2014 18:42
Avatar
Maros2470
Člen
Avatar
Odpovídá na Michal Štěpánek
Maros2470:

Potřeboval bych ještě poradit. Napsal jsem stránku detailu takto, ale načítá mi to jen první položku z databáze, nevíš kde mám chybu?
Stránka seznam:

<asp:SqlDataSource ID="seznamSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Appliance] WHERE ([SortingKey] = @SortingKey)">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="txbSortingKey" Name="SortingKey" PropertyName="Text" Type="String" DefaultValue="0" />
                    </SelectParameters>
                </asp:SqlDataSource>
                <br/>
                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ApplianceId" DataSourceID="seznamSource">
                    <Columns>
                        <asp:HyperLinkField DataNavigateUrlFields="ApplianceId" DataNavigateUrlFormatString="SpotrebicDetail.aspx?id={0}" NavigateUrl="SpotrebicDetail.aspx" Text="Detail" />
                        <asp:BoundField DataField="Customer" HeaderText="Customer" SortExpression="Customer" />
                        <asp:BoundField DataField="Place1" HeaderText="Place1" SortExpression="Place1" />
                        <asp:BoundField DataField="Place2" HeaderText="Place2" SortExpression="Place2" />
                        <asp:BoundField DataField="Place3" HeaderText="Place3" SortExpression="Place3" />
                        <asp:BoundField DataField="Place4" HeaderText="Place4" SortExpression="Place4" />
                        <asp:BoundField DataField="ApplianceId" HeaderText="ApplianceId" ReadOnly="True" SortExpression="ApplianceId" />
                        <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                        <asp:BoundField DataField="SortingKey" HeaderText="SortingKey" SortExpression="SortingKey" />
                        <asp:BoundField DataField="InvertoryNumber" HeaderText="InvertoryNumber" SortExpression="InvertoryNumber" />
                        <asp:BoundField DataField="SerialNumber" HeaderText="SerialNumber" SortExpression="SerialNumber" />
                        <asp:BoundField DataField="RevisionInterval" HeaderText="RevisionInterval" SortExpression="RevisionInterval" />
                        <asp:BoundField DataField="TakenIntoEvidence" HeaderText="TakenIntoEvidence" SortExpression="TakenIntoEvidence" />
                        <asp:BoundField DataField="Note" HeaderText="Note" SortExpression="Note" />
                        <asp:BoundField DataField="Group" HeaderText="Group" SortExpression="Group" />
                        <asp:BoundField DataField="ProtectionClass" HeaderText="ProtectionClass" SortExpression="ProtectionClass" />
                        <asp:BoundField DataField="MeasDate" HeaderText="MeasDate" SortExpression="MeasDate" />
                        <asp:BoundField DataField="MeasGlobalStatus" HeaderText="MeasGlobalStatus" SortExpression="MeasGlobalStatus" />
                        <asp:BoundField DataField="InspectorName" HeaderText="InspectorName" SortExpression="InspectorName" />
                        <asp:BoundField DataField="InspectorSecondName" HeaderText="InspectorSecondName" SortExpression="InspectorSecondName" />
                        <asp:BoundField DataField="InspectorLicense" HeaderText="InspectorLicense" SortExpression="InspectorLicense" />
                        <asp:BoundField DataField="DeviceSerialNum" HeaderText="DeviceSerialNum" SortExpression="DeviceSerialNum" />
                        <asp:BoundField DataField="DeviceType" HeaderText="DeviceType" SortExpression="DeviceType" />
                        <asp:BoundField DataField="DeviceCalibrationNum" HeaderText="DeviceCalibrationNum" SortExpression="DeviceCalibrationNum" />
                        <asp:BoundField DataField="DeviceCalibrationExpire" HeaderText="DeviceCalibrationExpire" SortExpression="DeviceCalibrationExpire" />
                        <asp:BoundField DataField="SupplFirm" HeaderText="SupplFirm" SortExpression="SupplFirm" />
                        <asp:BoundField DataField="SupplIc" HeaderText="SupplIc" SortExpression="SupplIc" />
                    </Columns>
                </asp:GridView>

stránka detail:

<asp:FormView ID="FormView1" runat="server" DataKeyNames="ApplianceId" DataSourceID="detailDataSource">
        <EditItemTemplate>
            Customer:
            <asp:TextBox ID="CustomerTextBox" runat="server" Text='<%# Bind("Customer") %>' />
            <br />
            Place1:
            <asp:TextBox ID="Place1TextBox" runat="server" Text='<%# Bind("Place1") %>' />
            <br />
            Place2:
            <asp:TextBox ID="Place2TextBox" runat="server" Text='<%# Bind("Place2") %>' />
            <br />
            Place3:
            <asp:TextBox ID="Place3TextBox" runat="server" Text='<%# Bind("Place3") %>' />
            <br />
            Place4:
            <asp:TextBox ID="Place4TextBox" runat="server" Text='<%# Bind("Place4") %>' />
            <br />
            ApplianceId:
            <asp:Label ID="ApplianceIdLabel1" runat="server" Text='<%# Eval("ApplianceId") %>' />
            <br />
            Name:
            <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
            <br />
            SortingKey:
            <asp:TextBox ID="SortingKeyTextBox" runat="server" Text='<%# Bind("SortingKey") %>' />
            <br />
            InvertoryNumber:
            <asp:TextBox ID="InvertoryNumberTextBox" runat="server" Text='<%# Bind("InvertoryNumber") %>' />
            <br />
            SerialNumber:
            <asp:TextBox ID="SerialNumberTextBox" runat="server" Text='<%# Bind("SerialNumber") %>' />
            <br />
            RevisionInterval:
            <asp:TextBox ID="RevisionIntervalTextBox" runat="server" Text='<%# Bind("RevisionInterval") %>' />
            <br />
            TakenIntoEvidence:
            <asp:TextBox ID="TakenIntoEvidenceTextBox" runat="server" Text='<%# Bind("TakenIntoEvidence") %>' />
            <br />
            Note:
            <asp:TextBox ID="NoteTextBox" runat="server" Text='<%# Bind("Note") %>' />
            <br />
            Group:
            <asp:TextBox ID="GroupTextBox" runat="server" Text='<%# Bind("Group") %>' />
            <br />
            ProtectionClass:
            <asp:TextBox ID="ProtectionClassTextBox" runat="server" Text='<%# Bind("ProtectionClass") %>' />
            <br />
            MeasDate:
            <asp:TextBox ID="MeasDateTextBox" runat="server" Text='<%# Bind("MeasDate") %>' />
            <br />
            MeasGlobalStatus:
            <asp:TextBox ID="MeasGlobalStatusTextBox" runat="server" Text='<%# Bind("MeasGlobalStatus") %>' />
            <br />
            InspectorName:
            <asp:TextBox ID="InspectorNameTextBox" runat="server" Text='<%# Bind("InspectorName") %>' />
            <br />
            InspectorSecondName:
            <asp:TextBox ID="InspectorSecondNameTextBox" runat="server" Text='<%# Bind("InspectorSecondName") %>' />
            <br />
            InspectorLicense:
            <asp:TextBox ID="InspectorLicenseTextBox" runat="server" Text='<%# Bind("InspectorLicense") %>' />
            <br />
            DeviceSerialNum:
            <asp:TextBox ID="DeviceSerialNumTextBox" runat="server" Text='<%# Bind("DeviceSerialNum") %>' />
            <br />
            DeviceType:
            <asp:TextBox ID="DeviceTypeTextBox" runat="server" Text='<%# Bind("DeviceType") %>' />
            <br />
            DeviceCalibrationNum:
            <asp:TextBox ID="DeviceCalibrationNumTextBox" runat="server" Text='<%# Bind("DeviceCalibrationNum") %>' />
            <br />
            DeviceCalibrationExpire:
            <asp:TextBox ID="DeviceCalibrationExpireTextBox" runat="server" Text='<%# Bind("DeviceCalibrationExpire") %>' />
            <br />
            SupplFirm:
            <asp:TextBox ID="SupplFirmTextBox" runat="server" Text='<%# Bind("SupplFirm") %>' />
            <br />
            SupplIc:
            <asp:TextBox ID="SupplIcTextBox" runat="server" Text='<%# Bind("SupplIc") %>' />
            <br />
            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Aktualizovat" />
            &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Storno" />
        </EditItemTemplate>
        <InsertItemTemplate>
            Customer:
            <asp:TextBox ID="CustomerTextBox" runat="server" Text='<%# Bind("Customer") %>' />
            <br />
            Place1:
            <asp:TextBox ID="Place1TextBox" runat="server" Text='<%# Bind("Place1") %>' />
            <br />
            Place2:
            <asp:TextBox ID="Place2TextBox" runat="server" Text='<%# Bind("Place2") %>' />
            <br />
            Place3:
            <asp:TextBox ID="Place3TextBox" runat="server" Text='<%# Bind("Place3") %>' />
            <br />
            Place4:
            <asp:TextBox ID="Place4TextBox" runat="server" Text='<%# Bind("Place4") %>' />
            <br />
            ApplianceId:
            <asp:TextBox ID="ApplianceIdTextBox" runat="server" Text='<%# Bind("ApplianceId") %>' />
            <br />
            Name:
            <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
            <br />
            SortingKey:
            <asp:TextBox ID="SortingKeyTextBox" runat="server" Text='<%# Bind("SortingKey") %>' />
            <br />
            InvertoryNumber:
            <asp:TextBox ID="InvertoryNumberTextBox" runat="server" Text='<%# Bind("InvertoryNumber") %>' />
            <br />
            SerialNumber:
            <asp:TextBox ID="SerialNumberTextBox" runat="server" Text='<%# Bind("SerialNumber") %>' />
            <br />
            RevisionInterval:
            <asp:TextBox ID="RevisionIntervalTextBox" runat="server" Text='<%# Bind("RevisionInterval") %>' />
            <br />
            TakenIntoEvidence:
            <asp:TextBox ID="TakenIntoEvidenceTextBox" runat="server" Text='<%# Bind("TakenIntoEvidence") %>' />
            <br />
            Note:
            <asp:TextBox ID="NoteTextBox" runat="server" Text='<%# Bind("Note") %>' />
            <br />
            Group:
            <asp:TextBox ID="GroupTextBox" runat="server" Text='<%# Bind("Group") %>' />
            <br />
            ProtectionClass:
            <asp:TextBox ID="ProtectionClassTextBox" runat="server" Text='<%# Bind("ProtectionClass") %>' />
            <br />
            MeasDate:
            <asp:TextBox ID="MeasDateTextBox" runat="server" Text='<%# Bind("MeasDate") %>' />
            <br />
            MeasGlobalStatus:
            <asp:TextBox ID="MeasGlobalStatusTextBox" runat="server" Text='<%# Bind("MeasGlobalStatus") %>' />
            <br />
            InspectorName:
            <asp:TextBox ID="InspectorNameTextBox" runat="server" Text='<%# Bind("InspectorName") %>' />
            <br />
            InspectorSecondName:
            <asp:TextBox ID="InspectorSecondNameTextBox" runat="server" Text='<%# Bind("InspectorSecondName") %>' />
            <br />
            InspectorLicense:
            <asp:TextBox ID="InspectorLicenseTextBox" runat="server" Text='<%# Bind("InspectorLicense") %>' />
            <br />
            DeviceSerialNum:
            <asp:TextBox ID="DeviceSerialNumTextBox" runat="server" Text='<%# Bind("DeviceSerialNum") %>' />
            <br />
            DeviceType:
            <asp:TextBox ID="DeviceTypeTextBox" runat="server" Text='<%# Bind("DeviceType") %>' />
            <br />
            DeviceCalibrationNum:
            <asp:TextBox ID="DeviceCalibrationNumTextBox" runat="server" Text='<%# Bind("DeviceCalibrationNum") %>' />
            <br />
            DeviceCalibrationExpire:
            <asp:TextBox ID="DeviceCalibrationExpireTextBox" runat="server" Text='<%# Bind("DeviceCalibrationExpire") %>' />
            <br />
            SupplFirm:
            <asp:TextBox ID="SupplFirmTextBox" runat="server" Text='<%# Bind("SupplFirm") %>' />
            <br />
            SupplIc:
            <asp:TextBox ID="SupplIcTextBox" runat="server" Text='<%# Bind("SupplIc") %>' />
            <br />
            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Vložit" />
            &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Storno" />
        </InsertItemTemplate>
        <ItemTemplate>
            Customer:
            <asp:Label ID="CustomerLabel" runat="server" Text='<%# Bind("Customer") %>' />
            <br />
            Place1:
            <asp:Label ID="Place1Label" runat="server" Text='<%# Bind("Place1") %>' />
            <br />
            Place2:
            <asp:Label ID="Place2Label" runat="server" Text='<%# Bind("Place2") %>' />
            <br />
            Place3:
            <asp:Label ID="Place3Label" runat="server" Text='<%# Bind("Place3") %>' />
            <br />
            Place4:
            <asp:Label ID="Place4Label" runat="server" Text='<%# Bind("Place4") %>' />
            <br />
            ApplianceId:
            <asp:Label ID="ApplianceIdLabel" runat="server" Text='<%# Eval("ApplianceId") %>' />
            <br />
            Name:
            <asp:Label ID="NameLabel" runat="server" Text='<%# Bind("Name") %>' />
            <br />
            SortingKey:
            <asp:Label ID="SortingKeyLabel" runat="server" Text='<%# Bind("SortingKey") %>' />
            <br />
            InvertoryNumber:
            <asp:Label ID="InvertoryNumberLabel" runat="server" Text='<%# Bind("InvertoryNumber") %>' />
            <br />
            SerialNumber:
            <asp:Label ID="SerialNumberLabel" runat="server" Text='<%# Bind("SerialNumber") %>' />
            <br />
            RevisionInterval:
            <asp:Label ID="RevisionIntervalLabel" runat="server" Text='<%# Bind("RevisionInterval") %>' />
            <br />
            TakenIntoEvidence:
            <asp:Label ID="TakenIntoEvidenceLabel" runat="server" Text='<%# Bind("TakenIntoEvidence") %>' />
            <br />
            Note:
            <asp:Label ID="NoteLabel" runat="server" Text='<%# Bind("Note") %>' />
            <br />
            Group:
            <asp:Label ID="GroupLabel" runat="server" Text='<%# Bind("Group") %>' />
            <br />
            ProtectionClass:
            <asp:Label ID="ProtectionClassLabel" runat="server" Text='<%# Bind("ProtectionClass") %>' />
            <br />
            MeasDate:
            <asp:Label ID="MeasDateLabel" runat="server" Text='<%# Bind("MeasDate") %>' />
            <br />
            MeasGlobalStatus:
            <asp:Label ID="MeasGlobalStatusLabel" runat="server" Text='<%# Bind("MeasGlobalStatus") %>' />
            <br />
            InspectorName:
            <asp:Label ID="InspectorNameLabel" runat="server" Text='<%# Bind("InspectorName") %>' />
            <br />
            InspectorSecondName:
            <asp:Label ID="InspectorSecondNameLabel" runat="server" Text='<%# Bind("InspectorSecondName") %>' />
            <br />
            InspectorLicense:
            <asp:Label ID="InspectorLicenseLabel" runat="server" Text='<%# Bind("InspectorLicense") %>' />
            <br />
            DeviceSerialNum:
            <asp:Label ID="DeviceSerialNumLabel" runat="server" Text='<%# Bind("DeviceSerialNum") %>' />
            <br />
            DeviceType:
            <asp:Label ID="DeviceTypeLabel" runat="server" Text='<%# Bind("DeviceType") %>' />
            <br />
            DeviceCalibrationNum:
            <asp:Label ID="DeviceCalibrationNumLabel" runat="server" Text='<%# Bind("DeviceCalibrationNum") %>' />
            <br />
            DeviceCalibrationExpire:
            <asp:Label ID="DeviceCalibrationExpireLabel" runat="server" Text='<%# Bind("DeviceCalibrationExpire") %>' />
            <br />
            SupplFirm:
            <asp:Label ID="SupplFirmLabel" runat="server" Text='<%# Bind("SupplFirm") %>' />
            <br />
            SupplIc:
            <asp:Label ID="SupplIcLabel" runat="server" Text='<%# Bind("SupplIc") %>' />
            <br />

        </ItemTemplate>
    </asp:FormView>

    <asp:SqlDataSource ID="detailDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Appliance]"></asp:SqlDataSource>



    </asp:Content>
 
Nahoru Odpovědět 14.9.2014 20:09
Avatar
Odpovídá na Maros2470
Michal Štěpánek:

Musíš mít v té stránce s detailem dotaz s "QueryStringPa­rameter"
např.:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [Appliance] WHERE ([ApplianceId] = @Applianceid)">
        <SelectParameters>
            <asp:QueryStringParameter Name="ApplianceId" QueryStringField="id" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
Editováno 14.9.2014 20:47
Nahoru Odpovědět 14.9.2014 20:46
Nikdy neříkej nahlas, že to nejde. Vždycky se totiž najde blbec, který to neví a udělá to...
Avatar
Maros2470
Člen
Avatar
Maros2470:

Díky už mi to šlape.

 
Nahoru Odpovědět 14.9.2014 23:22
Děláme co je v našich silách, aby byly zdejší diskuze co nejkvalitnější. Proto do nich také mohou přispívat pouze registrovaní členové. Pro zapojení do diskuze se přihlas. Pokud ještě nemáš účet, zaregistruj se, je to zdarma.

Zobrazeno 8 zpráv z 8.