私はitemtemplate
を含むgridview
を持っていて、itemtemplate
はlabel
を含んでいます。 text
をlabel
に置きたいのですが、値はcodebehind
です。 output
をgridview
に入力します。細かい作業 IMGラベルを使用してグリッドビューの行に値を動的に渡す方法は?
Proj_Title
とTotal_Issue
が、すべての行に対してlabel
テキストを設定する方法について説明します。ここ は私のaspxコードです:
<asp:GridView ID="g9" runat="server" OnRowDataBound="g9_RowDataBound" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Project_Title">
<ItemTemplate>
<asp:Label runat="server" Text='<%#Eval("proj_title") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Issue">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("Count") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="RESULT">
<ItemTemplate>
<asp:Label ID="issue" runat="server" ForeColor="Blue" Font-Size="Large" Width="200px" ></asp:Label>
<asp:Label ID="issue2" runat="server" ForeColor="Blue" Font-Size="Large" Width="200px" ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
count
値が2
その後、結果であるとき、私が欲しいASPX.CS
protected void Page_Load(object sender, EventArgs e)
{
SqlCommand cmd3 = new SqlCommand("USE SKDM SELECT proj_title , COUNT (*) as Count FROM Issue WHERE proj_title is NOT null GROUP BY proj_title", cnn);
SqlDataAdapter adp = new SqlDataAdapter(cmd3);
DataSet ds = new DataSet();
adp.Fill(ds);
cnn.Open();
cmd3.ExecuteNonQuery();
cnn.Close();
g9.DataSource = ds;
g9.DataBind();
}
protected void g9_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
SqlCommand cmd3 = new SqlCommand("USE SKDM SELECT proj_title , COUNT (*) as Count FROM Issue WHERE proj_title is NOT null GROUP BY proj_title", cnn);
cnn.Open();
SqlDataReader dr = cmd3.ExecuteReader();
int[] arr = new int[2];
while (dr.Read())
{
arr[0] = dr.GetInt32(1);
}
if (arr[0] == 2)
{
Label l3 = (Label)e.Row.FindControl("issue2");
string s = "BAD";
l3.Text = s;
}
dr.Close();
cnn.Close();
if (arr[0] == 2)
{
Label l2 = (Label)e.Row.FindControl("issue");
string s = "GOOD";
l2.Text = s;
}
if (arr[1] == 5)
{
Label ab = (Label)e.Row.FindControl("issue2");
ab.Text = "Poor";
}
}
}
がGood
行に対してResult
列に示されており、count
値が5
あるときに発生しますとなり、ラベルはResult
列になります。お気軽に
あなたはpageloadにGridViewのデータテーブルにバインドしないのはなぜ? – Developer
私はページload.Youで 'gridview'の値を取得したいのですが –
を教えてください。しかし、あなたは何が欲しいですか?グリッドビューでのデータのバインドについて混乱していると思います。 – Developer