我不知何故遇到了非常奇怪的错误。我的网格视图不会出现。这是我的代码 - 首先是我的.aspx
标记:
<asp:GridView ID="Zakljucani" runat="server" AutoGenerateColumns="False"
onrowcommand="Zakljucani_RowCommand" PageSize="300" Height="127px"
style=" visibility:visible; border-color:Red" >
<Columns>
<asp:BoundField DataField="KorisnickoIme" HeaderText="Korisnicko ime" Visible="true" />
<asp:BoundField DataField="Mail" HeaderText="Mail" Visible="true" />
<asp:BoundField DataField="DatumZakljucavanja"
HeaderText="Datum i vrijeme zaključavanja" />
<asp:BoundField DataField="HoursElapsed" HeaderText="Protekli sati" />
<asp:TemplateField HeaderText="Otključaj">
<ItemTemplate>
<asp:Button ID="Button1" CommandArgument='<%#Eval("KorisnickoIme")%>' runat="server" Enabled='<%#Convert.ToInt32(Eval("HoursElapsed"))>24%>' Text="Otključaj" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
这是我的代码
protected void Page_Load(object sender, EventArgs e)
{
GetData();
}
private void GetData()
{
string CS = ConfigurationManager.ConnectionStrings["Konekcija"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("SpZakljucaniRacuni", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
Zakljucani.DataSource = cmd.ExecuteReader();
Zakljucani.DataBind();
}
}
private void EnableUserAccount(string UserName)
{
string CS = ConfigurationManager.ConnectionStrings["Konekcija"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("OtkljucajZakljucaniRacun", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter paramUserName = new SqlParameter()
{
ParameterName = "@KorisnickoIme",
Value = UserName
};
cmd.Parameters.Add(paramUserName);
con.Open();
cmd.ExecuteNonQuery();
}
}
protected void Zakljucani_RowCommand(object sender, GridViewCommandEventArgs e)
{
EnableUserAccount(e.CommandArgument.ToString());
GetData();
}
问题是gridview没有出现。今天还好好的,后来就不行了。
不知道是不是有错误,还是绑定的时候有问题。希望我们会发现错误,如果有一个。