datagrid_itemcommand事件没有被解雇



我使用的是我的格式的数据杂志,该datagrid具有2个按钮,编辑和删除,但是这些事件没有被触发。我在代码中出错了哪里。我已经在vb.net中运行了相同的代码,但是在C#中转换后,它不起作用。plz帮助。

在从vb.net转换为c#的代码上,我还有其他更改需要做出其他更改。预先感谢!

private void dgjob_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
    try
    {
        switch (e.CommandName)
        {
            case "edit":
                try
                {
                    qry = "select ROLE from AV_USER_DETAILS where USER_ID='" + Session["user_name"] + "'";
                    cmd.Connection = con;
                    cmd.CommandText = qry;
                    con.Open();
                    if (Information.IsDBNull(cmd.ExecuteScalar()))
                    {
                        av_class.alert("User Not Permitted ", this);
                        con.Close();
                        return;
                    }
                    string st = cmd.ExecuteScalar().ToString();
                    if (!(st == "hod") & !(st == "Media_Planner"))
                    {
                        av_class.alert("User Not Permitted ", this);
                        con.Close();
                        return;

                    }
                    con.Close();
                    if (st == "hod")
                    {
                        goto mygo;
                    }
                    else
                    {
                        if (st == "Media_Planner")
                        {
                            goto mygo;
                        }
                        else
                        {
                            av_class.alert("User not Permitted", this);
                            return;
                        }
                    }
                }
                catch (Exception ex)
                {
                    av_class.alert("Error .", this);
                }
            mygo:
                ViewState["job_code"] = bll.RemoveSpecialChars(((Label)e.Item.FindControl("lbljobcode")).Text.Trim());

                //4 tables changed  av_creative_for_agency,av_datatable_one_for_ro,av_cmp_prd,av_datatable_two_for_ro used only once'
                DataTable dat = new DataTable();
                DAL o = new DAL();
                dat = o.GetDataForGrid("select top 1 job_code from av_creative_for_agency where job_code='" + ViewState["job_code"] + "'");
                if (dat.Rows.Count > 0)
                {
                    av_class.alert("Ro's are Created for this !So can't be Edited", this);
                    return;
                }

                if (chk_job(ViewState["job_code"].ToString()) == false)
                {
                    //alert("This Job already confirmed, so cannot be edited!", Me)
                    //Exit Sub
                    tb_campaign.Enabled = false;
                }
                retrive_from_DB(bll.RemoveSpecialChars(ViewState["job_code"].ToString()));
                tabjob.Visible = true;
                break;
            Case "delete"
                ViewState("job_code") = bll.RemoveSpecialChars(CType(e.Item.FindControl("lbljobcode"), Label).Text.Trim)
                If chk_job(ViewState("job_code")) = False Then
                    alert("This Job already confirmed, so cannot be deleted!", Me)
                    Exit Sub
                End If
                If del_draft(ViewState("job_code")) = False Then
                    alert("Error in processing!", Me)
                    Exit Sub
                End If
                tabjob.Visible = False
                alert("Draft deleted successfully!", Me)
        }
    }
    catch (Exception ex)
    {
    }
}


ASPX CODING OF THE DATAGRID
<asp:datagrid id="dgjob" runat="server" CssClass="davpdgdatagrid" 
                    PageSize="100" AutoGenerateColumns="False" ShowFooter="True" 
                    BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" 
                    BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal" 
                    HorizontalAlign="Center">
                        <AlternatingItemStyle CssClass="davpdgalt"></AlternatingItemStyle>
                        <ItemStyle CssClass="davpdgitem" HorizontalAlign="Center"></ItemStyle>
                        <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
                        <HeaderStyle Wrap="False" HorizontalAlign="Center" CssClass="davpdgheader" 
                            BackColor="#333333" Font-Bold="True" ForeColor="White"></HeaderStyle>
                        <Columns>
                            <asp:TemplateColumn>
                                <ItemTemplate>
                                    <asp:Button id="btnedit" runat="server" CssClass="btn btn-primary" Text="Edit" CausesValidation="False"
                                        CommandName="edit"></asp:Button>
                                </ItemTemplate>
                            </asp:TemplateColumn>
                            <asp:TemplateColumn>
                                <ItemTemplate>
                                    <asp:Button id="btndelete" runat="server" CssClass="btn btn-primary" Text="Delete" CausesValidation="False"
                                        CommandName="delete"></asp:Button>
                                </ItemTemplate>
                            </asp:TemplateColumn>
                            <asp:TemplateColumn HeaderText="Job Code">
                                <ItemTemplate>
                                    <asp:Label id="lbljobcode" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.job_code") %>'>
                                    </asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox id="TextBox2" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.job_code") %>'>
                                    </asp:TextBox>
                                </EditItemTemplate>
                            </asp:TemplateColumn>
                            <asp:BoundColumn DataField="job_name" HeaderText="Job Name"></asp:BoundColumn>
                            <asp:BoundColumn DataField="job_date" HeaderText="Job Date"></asp:BoundColumn>
                        </Columns>
                        <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" Mode="NumericPages" />
                        <SelectedItemStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
                    </asp:datagrid>

在您的aspx文件中,您无处呼叫" dgjob_itemcommand"方法,您希望在其中触发事件。

您必须在网格的onselectedIndexchanged事件上调用" dgjob_itemcommand"。

<asp:datagrid id="dgjob" runat="server" CssClass="davpdgdatagrid" 
                    PageSize="100" AutoGenerateColumns="False" ShowFooter="True" 
                    BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" 
                    BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal" 
                    HorizontalAlign="Center" OnSelectedIndexChanged="dgjob_ItemCommand">
                        <AlternatingItemStyle CssClass="davpdgalt"></AlternatingItemStyle>

我希望这会有所帮助。

相关内容

  • 没有找到相关文章

最新更新