如何让被嵌套在数据网格为String用户控件的值 [英] how to get the User control Value which is nested inside the datagrid to String

查看:87
本文介绍了如何让被嵌套在数据网格为String用户控件的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要访问用户控件的值,它是里面的数据present Grid.as如下图所示

I need to access the Value of User control which is present inside the data Grid.as shown below

其实我要的是一旦数据绑定到网格,它会检查是否有DataGrid的Expence列中的值,如果该值为null,则该用户控件将是可见的,其中用户可以选择价值将点击保存。
我的aspx code:

Actually what i want is once the data is bind to the grid it will check whether there is a value in the Expence column of the Datagrid if the value is null then the user control will be visible where user can select the value and will click save. my aspx code:

<asp:UpdatePanel ID="UPChargesGrid" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:DataGrid ID="dgDestination" runat="server" BorderWidth="1px" BorderColor="#FE9B00"
        BorderStyle="Solid" BackColor="White" Font-Names="Verdana" Font-Size="XX-Small AutoGenerateColumns="False" ShowFooter="FALSE" CellPadding="3"       align="center" Width="700px" OnItemCommand="dgDestination_Select"
                     <Columns>
                         <asp:BoundColumn DataField="mCHR_NUPKId" HeaderText="mFDD_mFRD_NUPKId" Visible="False"></asp:BoundColumn>
                         <asp:BoundColumn DataField="Income" HeaderText="Income"></asp:BoundColumn>
                         <asp:TemplateColumn HeaderText="Expence">
                              <ItemTemplate>
                                   <asp:Label ID="LBLEXcepceValue" runat="server" Text='<%# Eval("Expence") %>' > </asp:Label>
                                    <CC5:Charge ID="ChargeExpence" runat="server" />         
                              </ItemTemplate>
                        </asp:TemplateColumn>
                        <asp:TemplateColumn HeaderText="SAVE">
                             ItemTemplate>
                                   <asp:ImageButton runat="server" ID="IMGBTNSave" ImageUrl="~/AppImages/save.png"  CommandName="Save" />
                              </ItemTemplate>
                       </asp:TemplateColumn>
                    </Columns>
                    <PagerStyle HorizontalAlign="Left" ForeColor="#000066" BackColor="White" Mode="NumericPages"> </PagerStyle>
                 </asp:DataGrid>
         </contenttemplate>
</asp:UpdatePanel>  

我的CS code:

my CS code:

  protected void dgDestination_Select(Object sender, DataGridCommandEventArgs e)
{
    string expence = "";
    UPGridControls.Update();
    if (e.CommandName == "Save")
        {
           string FRDID = e.Item.Cells[0].Text;
           string income =  e.Item.Cells[1].Text;   
            if (FRDID != "")
             {
        Label LBLEXcepceValue = (Label)dgDestination.Items[vLoop].FindControl("LBLEXcepceValue");

                  if (LBLEXcepceValue.Text != income)
                    expence = (dgDestination.FindControl("ChargeExpence") as UserControl).ToString();
         using (LQMasterChargesMappingDataContext DB = new LQMasterChargesMappingDataContext())
                 {
                    var newFRD = new TB_MasterChargesMapping
                    {
                         mCHM_mCHR_NUPKId_Income =mobjGenlib.ConvertLong( GetChargeID(e.Item.Cells[1].Text.ToString())),
                         mCHM_mCHR_NUPKId_Expences = mobjGenlib.ConvertLong(GetChargeID(expence)),
                         mCHM_mCMP_NUUniqueId = mobjGenlib.ConvertLong(TXTCompanyID.Text),
                         mCHM_NUIsActive = 1
                    };
                    DB.TB_MasterChargesMappings.InsertOnSubmit(newFRD);
                    DB.SubmitChanges();

                    B_MasterChargesMapping MASLEVPREMAP = DB.TB_MasterChargesMappings.OrderByDescending(C => C.mCHM_NUPKId).Where(A => A.mCHM_NUIsActive == 1 && A.mCHM_mCMP_NUUniqueId == mobjGenlib.ConvertLong(TXTCompanyID.Text)).FirstOrDefault();
                  //Insert In UserLog Report
                     mobjGenlib.InsertUserlog("mCHM", mobjGenlib.ConvertString(MASLEVPREMAP.mCHM_NUPKId), "I");
                    TB_MasterChargesMapping NewFRD = (from P in DB.TB_MasterChargesMappings where P.mCHM_mCHR_NUPKId_Income == mobjGenlib.ConvertLong(GetChargeID(e.Item.Cells[1].Text.ToString())) && P.mCHM_NUIsActive == 1 select P).FirstOrDefault();
                    if (NewFRD != null)
                    {
                      Session["ODDID"] = mobjGenlib.ConvertString(NewFRD.mCHM_NUPKId);
                }
                 }
             }
       }
}

请帮我从等用户控件的字符串值。
先谢谢了。

please help me to et the value from user control to String. Thanks in advance.

推荐答案

您可以访问你这样的费用控制

You can access your expense control like this

var expense= e.Item.FindControl("ChargeExpence") as yourUserControl;

您可以定义用户控件,这实际上给你价值的公共财产。
然后,可以使用消费对象上面检索访问此属性。

You can define a public property in your user control, which actually gives you the value. You can then access this property using expense object retrieved above.

这篇关于如何让被嵌套在数据网格为String用户控件的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆