如何获取嵌套在datagrid中的用户控件的值为String [英] how to get the User control Value which is nested inside the datagrid to String

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

问题描述

我需要访问存在于数据Grid.as中的用户控件的值

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

其实我想要的是一旦数据绑定到网格,它将检查Datagrid的Expence列中是否有值如果值为空,则用户控件将可见,用户可以在其中选择该值,并单击保存。
我的aspx代码:

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代码:

  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);
                }
                 }
             }
       }
}


$ b $请帮助我从用户控制到String的价值。
提前感谢

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.

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

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