Gc这个项目的一些技术备忘点

Gc这个项目的一些技术备忘点:

 

一、利用ViewState存储List。

 

     dataList序列化存在   ViewState["dataList"]

     ViewState["dataList"]= JsonConvert.SerializeObject(dataList);

 

     在另一个动作需要时,对ViewState["dataList"]反序列化

     string s = ViewState["dataList"].ToString();

     var dataList = JsonConvert.DeserializeObject<List<JObject>>(s);

二、JObject 类型,没法用as 进行类型转换,采用

 

var moList = SQLHelper.ReaderToListJobject(dr);

foreach (dynamic item in moList)

       item是一制令单,有95个字段

string itemString = item.ToString();

强制类型转换  节省编程时间
    MF_MO moT = sonConvert.DeserializeObject<MF_MO>(itemString);

三、GridView1可以直接指向List<Object>

            GridView1.DataSourceID= null;

            GridView1.DataSource = selectList;

            GridView1.DataBind();

 

四、模态框在第三行指定宽度和高度。

    <!-- 模态框 -->

    <div class="modal fade text-center " id="selectRecord">

        <div class="modal-dialog ">

            <div class="modal-content" style="width: 700px; height: 700px;">

     模态框内加ajax控件,模态框操作时,不影响主页面

     <asp:UpdatePanel ID="UpdatePanel5" runat="server"><ContentTemplate>

弹出模态框语句:

 ScriptManager.RegisterStartupScript(this, this.GetType(), "abcd", "$('#selectMain').modal('show');", true);

 

五、在GridView内设样式white-space: nowrap;整个GridView内元素不换行。

自动加整洁的表格样式。CssClass="table table-striped table-active"

<asp:GridView ID="GridView_bgd" Style="white-space: nowrap;" CssClass="table table-striped table-active">

 

六、GridView加全选按钮。

    <asp:TemplateField HeaderText="选择">

             <HeaderTemplate>

                <asp:Label runat="server" ID="CheckAll" Text="选择" />

            </HeaderTemplate>

             <ItemTemplate>

                   <asp:CheckBox ID="CheckBox1" runat="server" />

             </ItemTemplate>

        </asp:TemplateField>

在外面加一个按钮

<asp:CheckBox CssClass="form-check" ID="CheckBox3" Style="margin-left: 0px;" runat="server" Text="全选" Width="72px" AutoPostBack="True" OnCheckedChanged="CheckBox3_CheckedChanged" />

按钮事件

        protected void CheckBox3_CheckedChanged(object sender, EventArgs e)

        {

            if (CheckBox3.Checked)

                for (int i = 0; i < this.GridView2.Rows.Count; i++)

                {

                    ((CheckBox)GridView2.Rows[i].FindControl("CheckBox1")).Checked = true;

                }

            else

            {

                for (int i = 0; i < this.GridView2.Rows.Count; i++)

                {

                    ((CheckBox)GridView2.Rows[i].FindControl("CheckBox1")).Checked = false;

                }

 

            }

        }

七、Tab选项卡。

     头部:

            <ul class="nav nav-tabs" id="myTab" role="tablist">

                <li class="nav-item" role="presentation">

                    <button class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#home-tab-pane" type="button" role="tab" aria-controls="home-tab-pane" aria-selected="true">出库详单</button>

                </li>

                <li class="nav-item" role="presentation">

                    <button class="nav-link " id="pg-tab" data-bs-toggle="tab" data-bs-target="#pg-tab-pane" type="button" role="tab" aria-controls="pg-tab-pane" aria-selected="true">物料汇总</button>

                </li>

                <li class="nav-item" role="presentation">

                    <button class="nav-link " id="sn-tab" data-bs-toggle="tab" data-bs-target="#sn-tab-pane" type="button" role="tab" aria-controls="sn-tab-pane" aria-selected="true">SN列表</button>

                </li>

            </ul>

  身部:

     <div class="tab-content" id="myTabContent">

    <div class="tab-pane fade show active" id="home-tab-pane" role="tabpanel" aria-labelledby="home-tab" tabindex="0">

                </div>

       <div class="tab-pane fade show " id="pg-tab-pane" role="tabpanel" aria-labelledby="pg-tab" tabindex="0">

                </div>

      <div class="tab-pane fade show " id="sn-tab-pane" role="tabpanel" aria-labelledby="sn-tab" tabindex="0">

                </div>

           </div>

八、GridView内设置 选择 按钮命令参数CommandArgument

<ItemTemplate>

<asp:LinkButton ID="LinkButton1" CommandArgument='<%Eval("ZC_PRD_NO")%>' runat="server" CausesValidation="False" OnClick="select_ZC_PRD_NO" CommandName="Select" Style="white-space: nowrap;" Text="选择">  </asp:LinkButton>

</ItemTemplate>

在事件里取出参数,直接是字符

        public void select_ZC_PRD_NO(object sender, EventArgs e)

        {

            LinkButton lbt = sender as LinkButton;

            var id = lbt.CommandArgument;

posted on 2023-05-12 15:42  宇宙毒蛇  阅读(19)  评论(0编辑  收藏  举报