私が作成した画像ボタンのID( 'titanBtn')は、自分のコードビハインドファイルで認識されないため、しばらくの間、これを行う方法を解明しようとしています。私は単純に 'titanBtn.ImageUrl ='と書くことができますが、コードビハインドは存在しないと言います。asp.netページのコードビハインドのイメージボタンのイメージURLを指定しますか?
私はこのコードでしようとしています。画像のファイル名を指定(適切な画像は、各オブジェクトの要素タイプにちなんで命名された)、及びIMAGEURLを指定連結した文字列でこれを置く。
<asp:Repeater ID="titanRptr" runat="server">
<ItemTemplate>
<table>
<tr class="tr1">
<td><%# Eval("TitanName") %></td>
<td>
<asp:ImageButton ID="titanBtn" runat="server" Width="100px" Height="100px" OnClick="titanBtn_Click" />
</td>
<td>Level: <%# Eval("char_lvl")%>
<br />
Step: <%# Eval("step")%>
<br />
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
コード
using (SqlCommand cmd2 = new SqlCommand("getElement", conn))
{
cmd2.CommandType = CommandType.StoredProcedure;
cmd2.Parameters.AddWithValue("@uid", titanElement);
using (SqlDataAdapter sda = new SqlDataAdapter(cmd2))
{
SqlDataReader reader;
conn.Open();
reader = cmd2.ExecuteReader();
while (reader.Read())
{
titanImage = Convert.ToString(reader["Element"]);
titanBtn.ImageUrl = "images/" + titanImage+ ".gif"; //"The name 'titanBtn' does not exist in the current context"
titanRptr
}
conn.Close();
}
}