This is a migrated thread and some comments may be shown as answers.

Radgrid - Need to pass columnID to update cell value

4 Answers 182 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kaushik
Top achievements
Rank 1
Kaushik asked on 27 Nov 2013, 03:47 PM

Hello team,

 I am working on a requirement in my application, where I have to save the values from the grid. The grid looks like below
      

Period

Amount

Column1

Column2

Column3

Column4

January

 33,445.00

 textbox

textbox

textbox

textbox

February

 22,000.00

textbox

textbox

textbox

textbox

March

 12,000.00

textbox

textbox

textbox

textbox

April

 

textbox

 textbox

textbox

textbox


The dataset the gets binded to the grid would contain periodID,periodname,amount,column1ID,column1value,column2ID,column2value,column3ID,column3value...
. The periodID would be the datakey value for the grid and the columns from column1  to column4 would be input text boxes. I want to bind the columnID values to the grid columns( column1ID to column1 , column2ID to column2....
).The users will enter some value in columns say column1 and I want to save the value entered in textbox to the database table. But the parameters I need to save would be periodID,textbox input and columnID.

I have two questions here , 

1. Can I bind columnIDs to columns (here in particular when it is having textbox)
2. If the columnIDs can be binded to the grid, can those values be retrieved when the text change event in the grid is called to save data.

I hope I am clear on the explanation. Could you please help me in this.

Thanks,
Kaushik

4 Answers, 1 is accepted

Sort by
0
Kaushik
Top achievements
Rank 1
answered on 28 Nov 2013, 02:58 PM
Can you please help me in this. I am eagerly waiting for your reply
0
Princy
Top achievements
Rank 2
answered on 29 Nov 2013, 06:10 AM
Hi,

I guess you want to bind a DataField to the Textboxes and get its value in ontextchanged event. Please take a look into the following code snippet.

ASPX:
<telerik:GridTemplateColumn UniqueName="Column1">
    <ItemTemplate>
        <asp:TextBox ID="txtColumn1" runat="server" Text='<%#Eval("column1ID")%>' AutoPostBack="true"
            OnTextChanged="txtColumn1_TextChanged"></asp:TextBox>
    </ItemTemplate>
</telerik:GridTemplateColumn>

C#:
protected void txtColumn1_TextChanged(object sender, EventArgs e)
{
    TextBox txt = (TextBox)sender;
    string value = txt.Text;
    //your code to update database
}

Thanks,
Princy.
0
Kaushik
Top achievements
Rank 1
answered on 29 Nov 2013, 02:16 PM
Thank you very much for your reply.

 I want to bind the columnID value but not to the text value of the textbox. I want to keep the textboxes for user input. And on the text changed event I want to pass the rowID, textbox value provided by user as input and columnID (which I don't want to show on the grid)
0
Princy
Top achievements
Rank 2
answered on 02 Dec 2013, 04:20 AM
Hi Kaushik,

You can set ColumnID as the DataKeyNames and access it in the TextChanged event using GetDataKeyValue. Please try the following code snippet.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server">
    <MasterTableView DataKeyNames="ColumnID">
        <Columns>        
            <telerik:GridTemplateColumn UniqueName="Column1">
                <ItemTemplate>
                    <asp:TextBox ID="txtColumn1" runat="server" AutoPostBack="true" OnTextChanged="txtColumn1_TextChanged"></asp:TextBox>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

C#:
protected void txtColumn1_TextChanged(object sender, EventArgs e)
 {
   TextBox txt = (TextBox)sender;
   string value = txt.Text;
   GridDataItem data = (GridDataItem)txt.NamingContainer;
   string columnId = data.GetDataKeyValue("ColumnID").ToString();
   //your code to update database
 }

Thanks,
Princy
Tags
Grid
Asked by
Kaushik
Top achievements
Rank 1
Answers by
Kaushik
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or