忍者ブログ

[PR]

×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

BoundFieldで構成されてるGridにcheckboxを追加

★aspx
<asp:gridview autogeneratecolumns="false" id="Grid1" runat="server">
<columns>
<asp:boundfield datafield="item1" headertext="1"></asp:boundfield>
<asp:boundfield datafield="item2" headertext="2"></asp:boundfield>
<asp:boundfield datafield="item3" headertext="3"></asp:boundfield>
<asp:boundfield datafield="item4" headertext="4"></asp:boundfield>
</columns>
</asp:gridview>

★aspx.vb
'適当なdatatableを返す
Dim dt As DataTable dt = createGrid.MakeGrid_Checkbox
Dim col1 As New System.Web.UI.WebControls.CheckBoxField
col1.HeaderText = "DelAdd1"
col1.DataField = "item5"
dt.Columns.Add(New DataColumn("item5", GetType(Boolean)))
'値は1 or 0
'0から始まるので、3番目を削除し、3番目に追加
Grid1.Columns.RemoveAt(2)
Grid1.Columns.Insert(2, col1)
Grid1.DataSource = dt Grid1.DataBind()

PR

ヘッダ固定

.Freezing
{
    color:Red;
    background-color:Black;
    font-weight:bold;
    text-align:left;
    border-width:0;
    position: relative;
    z-index: 10;
}

    <asp:Panel ID="Panel1" style="overflow:auto;height:250px" runat="server">
      <asp:GridView ID="grid" runat="server">
        <HeaderStyle CssClass="Freezing" Height="100px" />
      </asp:GridView>
    </asp:Panel>
 

GridView DropDown SelectedValueで該当する値がない場合

GridViewにDropDownを設定する。
GridViewには、普通のテーブルの値をバインド
DropDownには、マスタの値をバインド

通常は、DropDownに
<asp:DropDownList SelectedValue='<%# bind("CD") %>'
としてやれば、テーブルの値(CD)を選択して表示してくれる。

ただ、テーブルのCDがマスタのCDに存在しない場合、
エラーが起こる。

そのため、SelectedValue='<%# bind("CD") %>' は記述せず、
.vbで、SelectedValueを指定する。

Gridviewの「RowDataBound」

’グリッドからドロップダウンを探す
If e.Row.FindControl("DropDownList1") IsNot Nothing Then
 
  ddl = DirectCast(e.Row.FindControl("DropDownList1"), DropDownList)
  'ドロップダウンの値に、通常のテーブルのCDがあるか探す
  If ddl.Items.FindByValue(e.Row.DataItem("CD")) IsNot Nothing Then
    'あったら、指定する
    ddl.SelectedValue = e.Row.DataItem("CD")
  End If
End If
 

GridViewとDropDownList Radioボタンでデータソースを変更

ドロップダウン用にラジオボタンの数だけデータソースを作成

Gridの中にドロップダウンをつくっておく
ドロップダウンにバインドしておく

<asp:DropDownList ID="DropDownList2" runat="server" 
                        DataSourceID='<%# chengeDataSource %>'

.vb側で処理させる
   Protected Function chengeDataSource() As String
 
        Dim dataSource As String
 
        If RadioButton1.Checked = True Then
            dataSource = "SqlDataSourceDDL1"
        Else : RadioButton2.Checked = True
            dataSource = "SqlDataSourceDDL2"
        End If
 
        Return dataSource
 
    End Function

GridVewとDropDownListのバインドと更新

[ASP.NET]GridViewコントロールで選択ボックスを表示するには?[2.0、3.0、3.5、C#、VB
http://www.atmarkit.co.jp/fdotnet/dotnettips/816aspgridvwddlist/aspgridvwddlist.html

ListView と DropDownList
http://surferonwww.info/BlogEngine/post/2010/10/31/DropDwonList-in-InsertItemTemplate-of-ListView.aspx

デザインでGridを作る
ドロップダウンにするところを、TemplateFieldに変える
デザインで、Gridのテンプレートの編集を選択し、EditItemを選択する
テキストボックスを削除し、ドロップダウンを作成。
ドロップダウン用のデータソースを作成
表示する値と、使用する値を設定
※この時点で表示は出来ている。Gridとドロップダウンの連結は以下

ドロップダウンのタスクから、DataBindingsの編集を選択
SelectedValueを選択し、右側のカスタムバインドに「Bind("CD")」といった、
Gridのデータソースの値を設定
※この時点で連結までOK。ただ、データを編集して更新しても空白が登録される。

    Private Sub SqlDataSource1_Updating(sender As Object, e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles SqlDataSource1.Updating
        e.Command.Parameters("@NM").Value = _
            CType(Gridview1.Rows(Gridview1.EditIndex).FindControl("DropDownList1"), DropDownList).SelectedValue
    End Sub

強引に、パラメータに値をセットする
以上。




GridViewの幅固定

CSSで、「word-break:break-all;」を設定
(IE限定かも?要検証)

.WordBreak
{
word-break:break-all;
}
とか
table td
{
word-break:break-all;
}
など

ItemStyle-Width="10px"とすれば、
10pxで値が改行される

この場合、ヘッダは改行されない

ヘッダも改行するには、
HeaderStyle-Width="10px"も追加

GridViewやTableの線の制御

グリッドのラインを消す
<asp:GridView ID="GridView1" runat="server" GridLines="None">

あとは、線が欲しいとこに、CSSで設定する
・<asp:TemplateField ItemStyle-CssClass="td-all-solid">
・<td class=" td-top-solid">


CSS
.td-all-solid
{
border: 1px solid black;
}
.td-top-solid
{
border: 1px solid black;
border-top-style:solid;
}
.td-bottom-solid
{
border: 1px solid black;
border-bottom-style:solid;
}
.td-right-solid
{
border: 1px solid black;
border-right-style:solid;
}
.td-left-solid
{
border: 1px solid black;
border-left-style:solid;
}

カレンダー

04 2024/05 06
S M T W T F S
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

カテゴリー

フリーエリア

最新コメント

プロフィール

HN:
No Name Ninja
性別:
非公開

バーコード

ブログ内検索

P R