Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to bind the Date column dynamically in aspx based on the selected Date (Ex: Day1, Day2 etc).

XML
<asp:TemplateField HeaderText="Title">
                      <ItemTemplate>
                        <asp:Label ID="LabelRequest" runat="server" Text='<%# Bind("RequestTitle") %>'></asp:Label>
                    </ItemTemplate>
                    <ItemStyle Font-Bold="True" HorizontalAlign="Left" Width="120px" Wrap="True" />

                </asp:TemplateField>
                <asp:TemplateField HeaderText="Hours Spent" ItemStyle-Width="10%">
                    <ItemTemplate>
                        <asp:TextBox ID="TxtHoursSpent" Text='<%# Bind("HoursSpent") %>' runat="server" MaxLength="4" Width="25" ></asp:TextBox>
                    </ItemTemplate>
                    <ItemStyle Width="10%"></ItemStyle>



XML
I've the value for tat in c# variable(Ex: TodayDate). so the value matches the column name. I want to add that code behind value in aspx

Text='<%# Bind("HoursSpent") %>'
)... is it possible???????

Kindly help me.........

Thanx :)


XML
This is my caml query

qry.Query =
                @"<Where>
                              <And>
                                 <And>
                                    <And>
                                       <Eq>
                                          <FieldRef Name='Resource' />
                                          <Value Type='Integer'>
                                             <UserID />
                                          </Value>
                                       </Eq>
                                       <Eq>
                                          <FieldRef Name='Year' />
                                          <Value Type='Text'>" + Year + @"</Value>
                                       </Eq>
                                    </And>
                                    <Eq>
                                       <FieldRef Name='Month' />
                                       <Value Type='Text'>0" + TimeSheetMonth + @"</Value>
                                    </Eq>
                                 </And>
                                 <Eq>
                                    <FieldRef Name='Status' />
                                    <Value Type='Choice'>Open</Value>
                                 </Eq>
                              </And>
                           </Where>";

qry.ViewFields = @"<FieldRef Name='ID' /><FieldRef Name='RequestID' /><FieldRef Name='Title'/><FieldRef Name='" + columnDay + "'/>";
qry.ViewFieldsOnly = True;
SPListItemCollection listItems = list.GetItems(qry);


How can i bind the "columnDay" in aspx
Posted
Updated 27-Mar-15 3:08am
v2
Comments
bjay tiamsic 26-Mar-15 20:14pm    
Can you explain it clearer?
c_4less 26-Mar-15 20:58pm    
I have the column name stored in codebehind c# variable. I want to mark the value in aspx code.

ex: string mycolumn="something";
I want this mycolumn variable in aspx (Text='<%# Bind("HoursSpent") %>') code. so the value of mycolumn variable will act as a column in gridview

XML
In your markup you can do this:

<%# VariableName %>
 
Share this answer
 
Comments
c_4less 27-Mar-15 21:16pm    
So, the variable value (Ex:columnDay=Day1 ) Day1 column will get displayed in Gridview??????
C#
protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
         decimal mycolumn= 7.50; //i believe hours value should be decimal or int
         TextBox txtHrsSpentColumn = (TextBox)e.Row.FindControl("TxtHoursSpent");
         txtHrsSpentColumn.Text = mycolumn.ToString(); 
     }
}


Please check if this is what you need.
if the value of mycolumn variable is coming from a control change it to
C#
decimal mycolumn = Convert.ToDecimal(TextBox.Text);
 
Share this answer
 
Comments
c_4less 27-Mar-15 0:44am    
I've a codebehind lik below


qry.ViewFields = <fieldref name="ID"><fieldref name="RequestID"><fieldref name="Title"><fieldref name="" + columnDay + "">;

in this query, columnDay holds some value which is a column in gridview.
I want to bind this "columnDay" in aspx file also. so i can view the column based on the variable value


<itemtemplate>
<asp:TextBox ID="TxtHoursSpent" Text='<%# Bind("HoursSpent") %>' runat="server" MaxLength="4" Width="25" >
bjay tiamsic 27-Mar-15 1:13am    
Please send your query and how you bind you gridview.. if possible send all the codes you use for binding. we can't help yu if no codes are being shown
c_4less 27-Mar-15 1:56am    
int columnday=calendar1.selectedValue.Day
qry.ViewFields =
"select Id,Title,"+columnday+"from Timesheet";
I'm displaying 3 fields: ID, Title,Day (where day is passed using variable called columnday) I can able to put this values in aspx as
1. Text='<%# Bind("ID") %> for Id
2. Text='<%# Bind("Title") %> for Title
3. Text='<%# Bind("???") %> for Days.. How can i display it in grid aspx???
bjay tiamsic 27-Mar-15 2:11am    
select Id,Title,DATENAME(DW,CAST('"+columnday+"' AS INT)) as Day_ from Timesheet
Text='<%# Bind("Day_") %>
bjay tiamsic 27-Mar-15 2:13am    
This is applicable if you want to display DayName (i.e. Monday, Tuesday, etc) in you grid. But if you want to display only the number representation of the day make it
select Id,Title,'"+columnday+"' as Day_ from Timesheet
Text='<%# Bind("Day_") %>

use the word "AS" to name your column

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900