How to avoid double columns (predefined columns + selectcommand)?
I have a gridview with predefined columns and a selectcommand. Why do I get the columns twice? I want to keep the predefined columns and the selectcommand, but avoid getting the columns double.
<asp:GridView ID="gvMeldingen" runat="server"
AllowSorting="True" DataSourceID="MyDataSource"
onselectedindexchanged="GridView_SelectedIndexChanged"
AutoGenerateSelectButton="True">
<Columns>
<asp:BoundField DataField="Melder" HeaderText="Melder" />
<asp:BoundField DataField="Onderwerp" HeaderText="Onderwerp" />
<asp:TemplateField HeaderText="Omschrijving">
<ItemTemplate>
<div style="overflow:auto; width: 500px; height: 150px;">
<asp:Label ID="lblOmschrijving" runat="server" Text='<%# Bind("Omschrijving")%>'></asp:Label>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Fasedatum" HeaderText="Fasedatum" />
<asp:BoundField DataField="Niveau 1" HeaderText="Niveau 1" />
<asp:BoundField DataField="Niveau 2" HeaderText="Niveau 2" />
<asp:BoundField DataField="Outlook_ID" HeaderText="OutlookID" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="MyDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:HELPDESK_OUTLOOKConnectionString3 %>" />
This code shows how I use the selectcommand:
protected void MenuTabs1_MenuItemClick(object sender, MenuEventArgs e)
{
string select = @"SELECT
aanvrager.werknemersnaam AS Melder,
hd_aanvragen.aanvraag_titel AS Onderwerp,
hd_aanvragen.aanvraag_omschrijving AS Omschrijving,
hd_aanvraag_fase.fase_datum AS Fasedatum,
开发者_Go百科 hd_melding_niveau_1.niveau_omschrijving AS 'Niveau 1',
hd_melding_niveau_2.niveau_omschrijving AS 'Niveau 2',
hd_aanvragen.outlook_id
FROM hd_aanvragen
INNER JOIN hd_meldingen ON hd_meldingen.melding_id = hd_aanvragen.melding_id
INNER JOIN hd_melding_niveau_1 ON hd_melding_niveau_1.niveau1_id = hd_meldingen.niveau1_id
INNER JOIN hd_melding_niveau_2 ON hd_melding_niveau_2.niveau2_id = hd_meldingen.niveau2_id
INNER JOIN hd_aanvraag_fase ON hd_aanvraag_fase.aanvraag_id = hd_aanvragen.aanvraag_id
INNER JOIN hd_statussen ON hd_statussen.status_id = hd_aanvraag_fase.status_id
INNER JOIN hd_werknemers AS oplosser ON oplosser.werknemer_Id = hd_aanvraag_fase.werknemer_Id
INNER JOIN hd_werknemers AS aanvrager ON aanvrager.werknemer_Id = hd_aanvragen.werknemer_Id
WHERE hd_statussen.status_id = ";
int index = Int32.Parse(e.Item.Value);
multiTabs1.ActiveViewIndex = index;
int status = 0;
if (index == 1)
status = 2;
else if (index == 2)
status = 16;
else if (index == 3)
status = 17;
else if (index == 4)
status = 4;
MyDataSource.SelectCommand = select + status;
}
You have to add the AutoGenerateColumns property to your GridView with value "false". That will let the GridView know that no columns should be automatically generated during the bind process.
Good luck! :)
精彩评论