Link to home
Start Free TrialLog in
Avatar of JT_SIRO
JT_SIRO

asked on

Can't see cell values when I don't rebind on postback

I've been stuck on this for a half and day and don't know what is what now...  Here's the issue:
In page load, I loop through a system folder and populate a datatable with the filenames, and a few other text fields.  I then bind that to my Obout Grid control (like the .net Gridview, but pickier).

Then in my aspx page, I had a few template fields to display a textbox and a few check boxes, for each row.  This builds perfectly.  I am unable to get both the template control values and the plain text values in my btnSave_Click event.

When I don't bind my grid on postback, I'm able to see the texbox and checkboxes from my button click event.  But I can't see the filename field that I populated from my initial page_load.  That kind of makes sense.  But when I bind the grid on every post, I can no longer see the values of my textbox or checkboxes.  But I can see the filename field.  
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataTable dtFiles = new DataTable();
            DataColumn dc;
            bool isCleanFilename = true;

            // File Name
            dc = new DataColumn();
            dc.DataType = Type.GetType("System.String");
            dc.ColumnName = "Filename";
            dtFiles.Columns.Add(dc);

            // Username
            dc = new DataColumn();
            dc.DataType = Type.GetType("System.String");
            dc.ColumnName = "Username";
            dtFiles.Columns.Add(dc);

            // Status
            dc = new DataColumn();
            dc.DataType = Type.GetType("System.String");
            dc.ColumnName = "Status";
            dtFiles.Columns.Add(dc);

            // Directory
            dc = new DataColumn();
            dc.DataType = Type.GetType("System.String");
            dc.ColumnName = "Directory";
            dtFiles.Columns.Add(dc);

            // Add the row - loop through file list
            DataRow row;


            // Get usernames, compare for existence in Composers folders, then loop through them all, and dump files into DataTable
            string[] roles = new string[] { "SH_COMP", "SH_ADMIN", "SH_SUPER" };

            MembershipUserCollection mc = Membership.GetAllUsers(); //FindUsersByRole(roles);

            foreach (MembershipUser u in mc)
            {
                DirectoryInfo di = new DirectoryInfo("C:\\FTP\\Composers" + "\\" + u.UserName.ToString());

                if (di.Exists)
                {
                    FileInfo[] rgFiles = di.GetFiles("*.wav");
                    foreach (FileInfo fi in rgFiles)
                    {
                        dtFiles.Rows.Add(row);
                    }
                }
            }

            gvTracks.DataSource = dtFiles;
            gvTracks.DataBind();
            }
}



// Button save event which is getting textbox and checkbox, but not Username or Filename

    protected void btnSave_Click(object sender, EventArgs e)
    {
        string strSQL = "", strJob = "", strAction = "INI", Filename = "", Username = "";
        string Notes="", FilenameFormatted = "";
        int RecID = 0;

        //Create sql connection and command
        string cnnString;
        cnnString = ConfigurationManager.ConnectionStrings["SmashHausConnectionString"].ConnectionString;
        SqlConnection cn = new SqlConnection(cnnString);
        SqlCommand cmd = new SqlCommand();

        //Loop through gridview rows to find what Action was checked, then store in metadata and move files
        cn.Open();


        for (int i = 0; i < gvTracks.Rows.Count; i++)
        {
            // Check if Approved
            CheckBox chkApprove = (CheckBox)gvTracks.Rows[i].Cells[4].FindControl("chkApprove");
            if(chkApprove != null && chkApprove.Checked)
            {
                strAction = "Approved";
            }

            // Check if Revise
            CheckBox chkRevise = (CheckBox)gvTracks.Rows[i].Cells[4].FindControl("chkRevise");
            if (chkRevise != null && chkRevise.Checked)
            {
                strAction = "Revise";
            }

            // Check if Denied
            CheckBox chkDeny = (CheckBox)gvTracks.Rows[i].Cells[4].FindControl("chkDeny");
            if (chkDeny != null && chkDeny.Checked)
            {
                strAction = "Denied";
            }

            // Get the Job if any
            DropDownList ddJob = (DropDownList)gvTracks.Rows[i].Cells[5].FindControl("ddJobs");
            if ((ddJob != null) && (ddJob.SelectedItem.ToString() != "...Select Job"))
            {
                strJob = ddJob.SelectedItem.ToString();
                strAction = "Approved";  // Insert into meta just like Approved track, then add to job 
            }

            // Get Filename, Username and Notes
            Filename = gvTracks.Rows[i].Cells[0].Text;
            Username = gvTracks.Rows[i].Cells[2].Text;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of P1ST0LPETE
P1ST0LPETE
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JT_SIRO
JT_SIRO

ASKER

Thanks for the detailed reply P1.  I appreciate it.  But at first glance, it looks like what I did (forgive the sloppy code - I'm trying to rush this thing out the door).  I'll try to implement it tomorrow though.  I think it's in issue with the Obout grid, either have a bug or that I don't have it configured right.  It has a serialization property that when set to false allows m to see my template control values, but not the datafield elements.  And vise/versa, when serialization="true", I can see the datafield elements but not my template controls...  Uggg.

I've emailed their support, but haven't heard back yet.  If you have any ideas, please let me know, otherwise, I'm going to rip it out and got .net gridview.  I've attached my aspx code with the Obout grid below.
<cc1:Grid ID="gvTracks" runat="server" AutoGenerateColumns="false" Width="100%" Serialize="false" 
                  AllowAddingRecords="false" ShowFooter="true" AllowPageSizeSelection="false" AllowColumnResizing="true" 
                  AllowPaging="false" AllowSorting="true" FolderStyle="../OboutStyles/grid/style_2" 
                  EmbedFilterInSortExpression="true">
        <ScrollingSettings  ScrollHeight="352" />
        <Columns>                        
            <cc1:Column HeaderText="Play" DataField="Filename" HeaderAlign="left" Width="50">
                <TemplateSettings TemplateId="tmpPlayStop"/>
            </cc1:Column>
                      
            <cc1:Column HeaderText="File Name" Width="20%" Wrap="true">
                <TemplateSettings TemplateId="tmpFilename"/>
            </cc1:Column>
            
            <cc1:Column DataField="Username" HeaderText="Username" Width="10%" Wrap="true"></cc1:Column>                           

            <cc1:Column HeaderText="Notes" Width="270">
                <TemplateSettings TemplateId="tmpNotes" />
            </cc1:Column>   

            <cc1:Column HeaderText="Actions" Width="20%">
                <TemplateSettings TemplateId="tmpActions" />
            </cc1:Column>   

            <cc1:Column HeaderText="Submit To Job" Width="19%">
                <TemplateSettings TemplateId="tmpSubmit" />
            </cc1:Column>   

<%--            <cc1:Column HeaderText="Action" Width="28%" Index="4">
                <TemplateSettings TemplateId="tmpAction" />
            </cc1:Column>   --%>
        </Columns>

        <Templates>                        
            <cc1:GridTemplate runat="server" ID="tmpPlayStop">
                <Template>
                    <img id="imgPlay<%# Container.RecordIndex%>" src="../images/musicsearch/play.png" alt="Play" onmousedown="javascript:changeImage('<%# Container.Value.Replace("wav", "mp3")%>','<%# Container.RecordIndex%>', '<%# Convert.ToString(Container.DataItem["TrackTitle"]).Replace("'","987654")%>');" />
                </Template>
            </cc1:GridTemplate>   

            <cc1:GridTemplate runat="server" ID="tmpFilename">
                <Template>
                    <%# Container.DataItem["Filename"] %>
                </Template>
            </cc1:GridTemplate>               

            <cc1:GridTemplate runat="server" ID="tmpActions">
                <Template>  
                        Approve<asp:CheckBox ID="chkApprove" runat="server" />
                        Revise<asp:CheckBox ID="chkRevise" runat="server" />
                        Deny<asp:CheckBox ID="chkDeny" runat="server" />
                </Template>
            </cc1:GridTemplate>   

            <cc1:GridTemplate runat="server" ID="tmpSubmit">
                <Template>  
                    <asp:DropDownList ID="ddJobs" runat="server" DataSourceID="dsJobs" DataTextField="JobName" AppendDataBoundItems="true">
                    <asp:ListItem Selected="True">...Select Job</asp:ListItem>
                    </asp:DropDownList>
                </Template>
            </cc1:GridTemplate>   

            <cc1:GridTemplate runat="server" ID="tmpNotes">
                <Template>  
                    <cc2:OboutTextBox ID="txtNotes" runat="server" Text="" TextMode="multiline" Height="50" Width="260"></cc2:OboutTextBox>
                </Template>
            </cc1:GridTemplate>   
            
        </Templates>                
   </cc1:Grid>

Open in new window