- PR -

Datagrid内のCheckboxの値について

1
投稿者投稿内容
ターキッシュ
大ベテラン
会議室デビュー日: 2003/01/15
投稿数: 126
投稿日時: 2003-01-24 20:43
以前にもここに書き込みがありまして、その方法を使用したり、
色々試してみたのですが、どうにもDatagrid内のcheckboxの
値が取れません。

データグリッド
<asp:datagrid id="AllDisplayGrid" style="LEFT: 10px; POSITION: relative; TOP: 10px" runat="server" Font-Size="14px" AllowPaging="True" PagerStyle-HorizontalAlign="Right" AutoGenerateColumns="False" BorderWidth="0" AlternatingItemStyle-BackColor="#E2DEF6" ItemStyle-Height="20px" PagerStyle-Mode="NumericPages" PageSize="20" OnPageIndexChanged="ChangePage" Width="780px" ItemStyle-HorizontalAlign="left" ItemStyle-VerticalAlign="Top" ItemStyle-Font-Names="shift_jis,MS Pゴシック" OnItemCommand="FundName_Select_Grid" BackColor="#ffffff">
<AlternatingItemStyle BackColor="#E2DEF6"></AlternatingItemStyle>
<ItemStyle HorizontalAlign="Left" Height="20px" VerticalAlign="Top"></ItemStyle>
<Columns>
<asp:TemplateColumn>
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="White" BackColor="#ADB8F7"></HeaderStyle>
<ItemTemplate>
<asp:CheckBox ID="Delete_CheckBox" Runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="ファンド名">
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="White" BackColor="#ADB8F7"></HeaderStyle>
<ItemTemplate>
<asp:LinkButton id="Linkbutton1" Text='<%# DataBinder.Eval(Container.DataItem, "FUND_FORMAL_NM") %>' CommandName="select" runat="server" Font-Size=14px Font-Bold=True Font-Name="MS 明朝,MS P明朝体,FC明朝体-B" Width="320px" ForeColor=#0000ff />
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="FUND_CD" HeaderText="コード">
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="White" BackColor="#ADB8F7"></HeaderStyle>
</asp:BoundColumn>
</Columns>
<PagerStyle HorizontalAlign="Right"></PagerStyle>
</asp:datagrid></FONT>

<asp:button id="Delete_Button" style="LEFT: 10px; POSITION: relative; TOP: 1px" Runat="server" OnCommand="Delete_Cookie" Text="削除"></asp:button>

削除を押した際の関数
public void Delete_Cookie(object sender,System.Web.UI.WebControls.CommandEventArgs e){
string sTempFundCd;

for (int i=0; i<items.Count; i++)
{
  CheckBox cb= (CheckBox)items[i].FindControl("Delete_CheckBox");
  if((cb != null) && cb.Checked)
  {
処理文
  }
}
}

ここで、他の項目は取得できるのですが、どうしてもcheckboxの値がfalseのまま
になってしまいます。
お見せできるような表記の仕方ではありませんが、何故checkboxの値のみ取れない
のかが解らなくて困っています。
ご存知の方いらっしゃいましたら、よろしくご教授お願いします。



NothingButXMLInfoSet
大ベテラン
会議室デビュー日: 2002/07/16
投稿数: 116
投稿日時: 2003-01-24 21:49
次のコードで取れました。

<%@ Page Language="C#" %>
<html>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
string[] a = new string[256];
for (int i = 0; i < 256; i++)
a[0] = i.ToString();
AllDisplayGrid.DataSource = a;
AllDisplayGrid.DataBind();
}
}
void Delete_Cookie(object sender, CommandEventArgs e) {
foreach(DataGridItem item in AllDisplayGrid.Items) {
TableCell c = item.Cells[0];
c.Controls.Add(new LiteralControl(((CheckBox)c.Controls[1]).Checked.ToString()));
}
}
</script>
<body><form runat="server">
<asp:datagrid id="AllDisplayGrid" style="LEFT: 10px; POSITION: relative; TOP: 10px" runat="server" Font-Size="14px" AllowPaging="True" PagerStyle-HorizontalAlign="Right" AutoGenerateColumns="False" BorderWidth="0" AlternatingItemStyle-BackColor="#E2DEF6" ItemStyle-Height="20px" PagerStyle-Mode="NumericPages" PageSize="20" Width="780px" ItemStyle-HorizontalAlign="left" ItemStyle-VerticalAlign="Top" ItemStyle-Font-Names="shift_jis,MS Pゴシック" BackColor="#ffffff">
<%--OnItemCommand="FundName_Select_Grid" OnPageIndexChanged="ChangePage" --%>
<AlternatingItemStyle BackColor="#E2DEF6"></AlternatingItemStyle>
<ItemStyle HorizontalAlign="Left" Height="20px" VerticalAlign="Top"></ItemStyle>
<Columns>
<asp:TemplateColumn>
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="White" BackColor="#ADB8F7"></HeaderStyle>
<ItemTemplate>
<asp:CheckBox ID="Delete_CheckBox" Runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="ファンド名">
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="White" BackColor="#ADB8F7"></HeaderStyle>
<ItemTemplate>
<%--<asp:LinkButton id="Linkbutton1" Text='<%# DataBinder.Eval(Container.DataItem, "FUND_FORMAL_NM") %>' CommandName="select" runat="server" Font-Size=14px Font-Bold=True Font-Name="MS 明朝,MS P明朝体,FC明朝体-B" Width="320px" ForeColor=#0000ff /> --%>
<asp:LinkButton id="Linkbutton1" Text='Dummy' CommandName="select" runat="server" Font-Size=14px Font-Bold=True Font-Name="MS 明朝,MS P明朝体,FC明朝体-B" Width="320px" ForeColor=#0000ff />
</ItemTemplate>
</asp:TemplateColumn>
<%-- <asp:BoundColumn DataField="FUND_CD" HeaderText="コード">
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="White" BackColor="#ADB8F7"></HeaderStyle>
</asp:BoundColumn> --%>
</Columns>
<PagerStyle HorizontalAlign="Right"></PagerStyle>
</asp:datagrid></FONT>

<asp:button id="Delete_Button" style="LEFT: 10px; POSITION: relative; TOP: 1px" Runat="server" OnCommand="Delete_Cookie" Text="削除"></asp:button>
</form></body></HTML>
ターキッシュ
大ベテラン
会議室デビュー日: 2003/01/15
投稿数: 126
投稿日時: 2003-01-25 01:04
御返答ありがとうございました。
月曜に試してみたいと思いますが、恐らく大丈夫だと思います。
literalを使用するんですね。勉強になりました。
今後もよろしくご指導お願いします。
1

スキルアップ/キャリアアップ(JOB@IT)