私はデータベースからデータを取得するgridviewを持っています。
ここに.NETコードがあります。たくさんの列があり、ここにテンプレートがあります:選択肢は、私が話しているものです。Gridviewはデータベースの値の代わりにTextを表示する必要があります
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowPaging="True" CellPadding="4" DataKeyNames="EmpID" ForeColor="#333333" GridLines="None" style="margin-right: 81px" Width="1174px" >
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField HeaderText="Choice" SortExpression="Choice">
<EditItemTemplate>
<asp:DropDownList ID="DropDownChoice" Text='<%# Bind("Choice") %>' runat="server" Width="60px">
<asp:ListItem Text="No" Value="0"></asp:ListItem>
<asp:ListItem Text="Yes" Value="1"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblChoice" runat="server" Text='<%# Bind("Choice") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
ここで、EditItemTemplateでは、ユーザーはデータベース上の前記データを編集することができます。私はドロップダウンリストを使用して、私はテキストを示すのトラブルを抱えていないか、はい、テキストが、データベースに保存されます値はまだ0と1
<EditItemTemplate>
<asp:DropDownList ID="DropDownChoice" Text='<%# Bind("Choice") %>' runat="server" Width="60px">
<asp:ListItem Text="No" Value="0"></asp:ListItem>
<asp:ListItem Text="Yes" Value="1"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
を表示することができますどこで、一度それが実行されると、Gridviewではい。あなたはここで見ることができるようにItemTemplateにコードです:
<ItemTemplate>
<asp:Label ID="lblChoice" runat="server" Text='<%# Bind("Choice") %>'></asp:Label>
</ItemTemplate>
Please suggest a way/method to show No/Yes on the ItemTemplate/Gridview section once executed. Thanks (let me know if you might need the C# code to bind data on the gridview)
注: 私はこのquestionに答えたRowDataBoundイベントを試してみました。 ここにコード:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
System.Data.DataRow dr = ((System.Data.DataRowView)e.Row.DataItem).Row;
if (dr["Choice"].ToString() == "0")
{
((Label)e.Row.FindControl("lblChoice")).Text = "No";
}
else if (dr["Choice"].ToString() == "1")
{
((Label)e.Row.FindControl("lblChoice")).Text = "Yes";
}
}
}
しかし、それは動作しません。何か不足していますか? <ItemTemplate>
タグに何かを含める必要がありますか?
の可能性のある重複した[GridViewの表示の代わりに値のテキスト](http://stackoverflow.com/questions/6702062/gridview-display-the-text-instead-of-values) – iceDragon
@iceDragon私が実際に持っていますその記事からRowDataBoundイベントを試しましたが、私はそれが.NETにどのように呼び出すのか答えを指摘していたのではないかと心配しました。どのようにするか知っていますか?ありがとう(私もこの質問を編集し、これを含むでしょう) – wolfQueen
この asp:GridView>のようにイベントをGridViewツールに追加します。 –
iceDragon