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

[Solved] How to add browsed file path to radGrid?

1 Answer 117 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ram
Top achievements
Rank 1
Ram asked on 06 May 2009, 07:04 AM

Hi, Iam having a scenario like this

on my webform I am having a combobox, a uploading file control,a Add button and a radGrid(it is having two columns combobox value column and fileNmae) .
In my combobox it is having some values (say A,B and C), I select a value from combobox and against that I browse for a file, after browsing a file when I click on Add button the combox value and the file path which is browsed should appear in radGrid.
How could I achieve this and one more thing one combobox selected value can have multiple files against them.

my source code is as follows :

<p><asp:Label ID="lblDocName" Text="Document Name" runat="server" /></p>
    <p><radG:RadComboBox ID="ddlDocName" runat="server" /></p>
    </div>
    <div>
    <p><asp:Label ID="lblAttachDoc" Text="Attach Document" runat="server" /></p>
    <p><asp:FileUpload ID="uplFileAttach" runat="server" Width="200px" /></p>
    </div>
    </div>
   
   
    <div >
    <asp:Button  ID="btnAdd" Text="Add" runat="server" />
    </div>
   
    
    <div>
    <radG:RadGrid ID="rgDocument" runat="server" Skin="Default" EnableEmbeddedSkins="False" Width="570px"  GridLines="None">
        <MasterTableView>
            <NoRecordsTemplate>
            </NoRecordsTemplate>
            <ExpandCollapseColumn>
                <HeaderStyle Width="20px" />
            </ExpandCollapseColumn>
            <RowIndicatorColumn>
                <HeaderStyle Width="20px" />
            </RowIndicatorColumn>
        </MasterTableView>
     </radG:RadGrid>
    </div>


thanks,

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 06 May 2009, 09:48 AM
Hello Ram,

You can create a datatable with required number of columns on the initial load of the page. In the NeedDataSource event of the grid, save the DataTable in a session variable which should be bound to the grid. And on the Button click event, you can add rows to the datatable,set the column values to the RadComboBox Selected Value and FileName and then bind the grid to the datatable.Try out the following code sample to understand better:
c#:
public DataTable dt;  
    protected void Page_Load(object sender, EventArgs e)  
    {  
        if (IsPostBack && ViewState["dt"] == null)  
        {  
            dt = new DataTable();  
            dt.Columns.Add("col1");  
            dt.Columns.Add("col2");  
        }  
        else  
        {  
            dt = (DataTable)ViewState["dt"];  
        }  
    }  
    protected void RadGrid1_NeedDataSource(object source, Telerik.WebControls.GridNeedDataSourceEventArgs e)  
    {  
        if (IsPostBack)  
        {  
            ViewState["dt"] = dt;  
            dt = (DataTable)ViewState["dt"];  
            RadGrid1.DataSource = dt;  
        }  
    }  
  
    protected void btnAdd_Click(object sender, EventArgs e)  
    {  
        DataTable dt = (DataTable)ViewState["dt"];  
        ViewState["dt"] = AddRow(dt);  
        RadGrid1.Rebind();   
    }  
  
    private DataTable AddRow(DataTable dt)  
    {  
        DataRow dr = dt.NewRow();  
        dr[0] = RaddlDocName.SelectedItem.Text; 
        dr[1] = uplFileAttach.PostedFile.FileName; 
        dt.Rows.Add(dr);  
        return dt;  
    }  

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