开发者

About ASP.NET Gridview

Hi I ne开发者_高级运维ed help implementing a logic using Gridview control in c#.

I have a gridview and it has many rows. Each row has a Button to click for the user. On each button click i am updating the selected record in the database. Now once row is updated, I need to hide that button to prevent reaction just for that particular row.

1. If i use this

<asp:CommandField ShowEditButton="True" EditText="select" />

, I can't make this hide. 2. If I use this

<asp:TemplateField HeaderText="Your Action">
  <ItemTemplate>
    <asp:Button
        ID="btnAccept"
        runat="server"
        Text="Accept" 
        OnClientClick="return confirm('Are you sure you want to Accept this offer?');" 
        onclick="btnAccept_Click" />
  </ItemTemplate>
</asp:TemplateField>

, I can't get the selected row index.

I hope i have cleared what i wanna ask. Thanks in advance.


Use Button control's CommandArgument property specify the row user clicked :

<asp:TemplateField HeaderText="Your Action">
  <ItemTemplate>
    <asp:Button
        ID="btnAccept"
        runat="server"
        Text="Accept" 
        OnClientClick="return confirm('Are you sure you want to Accept this offer?');" 
        CommandName="Accept"
        CommandArgument='<%# Eval("RowId") %>'
        onclick="btnAccept_Click" />
  </ItemTemplate>
</asp:TemplateField>

At code behind :

void btnAccept_Click(Object sender, CommandEventArgs e) 
{
    if (e.CommandName == "Accept")
    {
       string rowId = e.CommandArgument;
    }
}


Continuing on Canavars solution for 1):

void btnAccept_Click(Object sender, CommandEventArgs e) 
{
    if (e.CommandName == "Accept")
    {
       string rowId = e.CommandArgument;
       ((Button)sender).Visible = false;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜