利用CommandArgument 属性获取 datalist的中 控件数据绑定

利用CommandArgument 属性获取 datalist的中 控件数据绑定

 

aspx中的datalist标记语言:


            <asp:DataList ID="DataList1" runat="server" Width="500px" Height="1107px">
                <ItemTemplate>
                    <table width="100%">
                        <tr>
                            <td rowspan="3" style="width: 38%; height: 8px;" valign="top">
                                <asp:Image ID="ImgPerson" runat="server" Height="100px" Width="80px" ImageUrl='<%#"ShowUserPhoto.aspx?id="+Eval("message_id")  %>'
                                   /></td>
                            <td style="height: 20px; width: 18%;">
                                &nbsp; &nbsp;
                                <asp:Label ID="LPerson" runat="server" Font-Names="宋体" Font-Size="Small" Text='<%# Eval("message_author_name") %>'></asp:Label></td>
                            <td style="height: 20px; width: 18%;" align="center">
                                <asp:Label ID="LTime" runat="server" Font-Names="宋体" Font-Size="Small" Text='<%# Eval("message_date") %>'></asp:Label></td>
                            <td style="width: 7%; height: 20px" align="right">
                                <asp:Button ID="BtnReply" runat="server" Height="22px" OnClick="BtnReply_Click"
                                    Text="回复" Width="42px" CommandArgument='<%# Eval("message_author_name") %>' />&nbsp;
                                <asp:Button ID="BtnDelete" runat="server" OnClick="BtnDelete_Click" Text="删除" CommandArgument='<%# Eval("message_id") %>' />
                                &nbsp;&nbsp; &nbsp;
                            </td>
                        </tr>
                        <tr>
                            <td colspan="3" rowspan="2" style="height: 39px; width: 40%;" align="left">
                                <asp:Label ID="LMessage" runat="server" Font-Names="宋体" Font-Size="Small" Height="60px"
                                    Text='<%# Eval("message_content") %>' Width="369px"></asp:Label></td>
                        </tr>
                        <tr>
                        </tr>
                        <tr>
                            <td colspan="4" rowspan="1" valign="top" style="height: 14px">
                                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
                                &nbsp;&nbsp;<br />
                                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;
                                &nbsp; &nbsp; &nbsp;</td>
                        </tr>
                    </table>
                    &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;
                </ItemTemplate>
            </asp:DataList></td>

 

获取datalist中控件的数据绑定,删除记录

aspx.cs删除记录代码:

 

protected void BtnDelete_Click(object sender, EventArgs e)
    {
        String connectionString = ConfigurationManager.ConnectionStrings["communciationPlatformConnectionString"].ConnectionString;
        String sql = "DeleteMessage";
        SqlConnection connection = new SqlConnection(connectionString);

        SqlCommand command = new SqlCommand(sql, connection);
        command.CommandType = CommandType.StoredProcedure;

        SqlParameter paramMessageId = new SqlParameter("@message_id", SqlDbType.Int);
        Button b = (Button)sender;
        int s = Convert.ToInt32(b.CommandArgument);
        paramMessageId.Value = s;
        command.Parameters.Add(paramMessageId);

        connection.Open();
        command.ExecuteNonQuery();
        connection.Close();

        indexListBind();//重新绑定
    }

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值